Lập chỉ mục nghịch đảo (invertedindex) và tìm kiếm trên tập tài liệu lớn

29 632 4
Lập chỉ mục nghịch đảo (invertedindex) và tìm kiếm trên tập tài liệu lớn

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Lập chỉ mục nghịch đảo (invertedindex) và tìm kiếm trên tập tài liệu lớnSử dụng Hadoop và Mapreducegiả lập 1 máy tính, hệ điều hành Linux (bản phân phối Ubuntu 16.04, RAM 5GB, ổ cứng 50GB).Vận dụng được mô hình MapReduce vào bài toán đơn giản.Hoàn thành phạm vi bài toán đặt ra: lập chỉ mục nghịch đảo và tìm kiếm trên chỉ mục.Do điều kiện chạy thử nghiệm còn nhiều hạn chế nên chưa phát huy được ưu điểm của mô hình lập trình MapReduce.

TRƯỜNG ĐẠI HỌC CẦN THƠ LOGO KHOA CÔNG NGHỆ THÔNG TIN & TRUYỀN THÔNG BIG DATA Lập mục nghịch đảo (inverted-index) tìm kiếm tập tài liệu lớn GIẢNG VIÊN: HỌC VIÊN THỰC HIỆN: TS PHAN THƯỢNG CANG Lớp cao học - HTTT-K24 LÊ THỊ HỒNG CHIÊU - M2517001 PHAN THỊ THÚY KIỀU - M2517009 Lập mục nghịch đảo tìm kiếm tập tài liệu lớn NỘI DUNG Phạm vi thực Giải thuật Inverted Index Search Demo chương trình Kết luận Tài liệu tham khảo Hướng dẫn thực hành PHẠM VI THỰC HIỆN  Lập mục nghịch đảo đơn giản theo mơ hình MapReduce  Tập liệu input: định dạng txt  Cấu trúc mục:(không xếp danh sách docID) [tab] [space] … [tab] [space] … Ví dụ: Line 1: term1 doc1.txt doc2.txt … Line 2: term2 doc2.txt doc5.txt … PHẠM VI THỰC HIỆN  Tìm kiếm đơn giản tập mục nghịch đảo theo mô hình MapReduce (duyệt qua tất nội dung mục, khơng áp dụng kỹ thuật tìm kiếm để tăng tốc độ)  Cấu trúc lưu trữ kết tìm kiếm: tìm thấy từ hiển thị từ với danh sách docID chứa từ tìm kiếm [tab] [space] … [tab] [space] … 2.1 Inverted Index (tổng quát) Documents to be indexed Friends, Romans, countrymen Tokenizer Friends Romans Token stream Countrymen Linguistic modules Modified tokens friend roman Indexer Inverted index countryman friend roman countryman 13 16 2.1 Inverted Index: áp dụng cho toán Tokenizer (term, docID) Sort by term Inverted Index (Dictionary and Postings) 2.1 Indexer steps: Tokenizer Doc Doc I did enact Julius Caesar I was killed i' the Capitol; Brutus killed me So let it be with Caesar The noble Brutus hath told you Caesar was ambitious 2.1 Indexer steps: Sort 2.1 Indexer steps: Dictionary & Postings  Multiple term entries in a single document are merged  Split into Dictionary and Postings 2.1 Inverted Index - MapReduce Input, Splitting Mapper class Reducer class Mapping Tokenizer (term, docID) Shuffling Sort by term Reducing Inverted Index (Dictionary and Postings) 2.2 Search – MapReduce: Map Map(k1: id of row in the index file, v1: a line of text in the index file){ index=v1.split(“\t”); for(i=1;i 0){ listdocID = listdocID + " " + docID; }else listdocID = listdocID + docID; } //emit ~ Output(k2: word, v3: listdocID) context.write(key, new Text(listdocID)); } } 2.3 Inverted Index – Java code: Driver class public class InvertedIndexDriver { public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); Job job = Job.getInstance(conf, "Inverted Index"); job.setJarByClass(InvertedIndexDriver.class);//class contains main function job.setMapperClass(InvertedIndexMapper.class); job.setCombinerClass(InvertedIndexReducer.class); job.setReducerClass(InvertedIndexReducer.class); job.setOutputKeyClass(Text.class);//type data of key ~ key's output type of reduce job.setOutputValueClass(Text.class);//type data of value ~ value's output type of reduce FileInputFormat.addInputPath(job, new Path(args[0])); FileOutputFormat.setOutputPath(job, new Path(args[1])); //thiet lap so reducer job.setNumReduceTasks(2); System.exit(job.waitForCompletion(true) ? : 1); } } 2.3 Search – Java code: Mapper class public class SearchMapper extends Mapper { String [] fields; String query=""; String[] index; //code read query: code dat ngoai ham map de tranh lap lai nhieu lan Mapper goi lai ham map public void setup(Context context) { Configuration conf = context.getConfiguration(); String queryPath = conf.get("queryPath"); String lineQuery=null; //read contents of query file try { Path path = new Path(queryPath); FileSystem fileSystem = FileSystem.get(new Configuration()); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileSystem.open(path))); while ((lineQuery = bufferedReader.readLine()) != null) { if(query.length()>0) { query=query + " " + lineQuery; }else { query=lineQuery;//lap lan dau tien } } fields= query.toString().split(" "); //Tách dòng truy vấn } catch (IOException e) { e.printStackTrace(); } 2.3 Search – Java code: Mapper class public void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException { index = value.toString().split("\t"); //Tach tung dong chi muc for (String field : fields) { if (field.toLowerCase().equals(index[0])) context.write(new Text(field), new Text(index[1])); } }//end map }//end mapper 2.3 Search – Java code: Reducer class public class SearchReducer extends Reducer { public void reduce(Text key, Iterable values, Context context) throws IOException, InterruptedException { //ban chat mot key duoc gom ve cung mot reducer ma chi muc thi da nhom lai theo key roi //nen o day chi co nhat mot dong gom key, value tuong ung nen ko can phai nhom lai nua //emit ~ Output(k2: word, v3: listdocID) for(Text docIDs : values){ context.write(key, new Text("\t"+docIDs)); } }//end reduce }//end SearchReducer 2.3 Search – Java code: Driver class public class SearchDriver { public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length != 3) { System.err.println("args include: "); System.exit(2); } String queryPath=otherArgs[2];//lay duong dan chuoi query conf.set("queryPath", queryPath); Job job = Job.getInstance(conf, "Search Engine"); job.setJarByClass(SearchDriver.class);//class contains main function job.setMapperClass(SearchMapper.class); job.setCombinerClass(SearchReducer.class); job.setReducerClass(SearchReducer.class); job.setOutputKeyClass(Text.class);//type data of key ~ key's output type of reduc job.setOutputValueClass(Text.class);//type data of value ~ value's output type of reduce FileInputFormat.addInputPath(job, new Path(args[0])); FileOutputFormat.setOutputPath(job, new Path(args[1])); System.exit(job.waitForCompletion(true) ? : 1); } } Demo chương trình Đề mơ trực tiếp: + Số lượng: files (~19 kB) + Định dạng: plain text (.txt) Thiết bị: giả lập máy tính, hệ điều hành Linux (bản phân phối Ubuntu 16.04, RAM 5GB, ổ cứng 50GB) Kết demo: + Số lượng: 1.364 files (~4.3MB) + Định dạng: plain text (.txt) + Thời gian xử lý: ~ 2.5 KẾT LUẬN  Vận dụng mơ hình MapReduce vào tốn đơn giản  Hồn thành phạm vi tốn đặt ra: lập mục nghịch đảo tìm kiếm mục  Do điều kiện chạy thử nghiệm nhiều hạn chế nên chưa phát huy ưu điểm mơ hình lập trình MapReduce KẾT LUẬN Hướng phát triển: Tìm kiếm với đầu vào nhiều câu query (~ với dòng file query câu query) Thử nghiệm hệ thống phân tán với liệu lớn TÀI LIỆU THAM KHẢO [1] Thang Le Dinh, Thuong-Cang Phan, “Towards an Architecture for Big Data Driven Knowledge Management Systems,” AMCIS 2016 [2] J Dean and S Ghemawat, “MapReduce: Simplified Data Processing on Large Clusters,” in Proceedings of the 6th Conference on Symposium on Opearting Systems Design & Implementation - Volume 6, CA, USA, 2004, pp 137–150 [3] https://acadgild.com/blog/building-inverted-index-mapreduce/ [4] https://stackoverflow.com/questions/47223444/inverted-index-with-mapreduce HƯỚNG DẪN THỰC HÀNH LOGO

Ngày đăng: 24/03/2019, 09:24

Từ khóa liên quan

Mục lục

  • Lập chỉ mục nghịch đảo và tìm kiếm trên tập tài liệu lớn

  • NỘI DUNG

  • 1. PHẠM VI THỰC HIỆN

  • Slide 4

  • 2.1. Inverted Index (tổng quát)

  • 2.1. Inverted Index: áp dụng cho bài toán

  • 2.1. Indexer steps: Tokenizer

  • 2.1. Indexer steps: Sort

  • 2.1. Indexer steps: Dictionary & Postings

  • 2.1. Inverted Index - MapReduce

  • 2.1. Inverted Index – MapReduce: Mô hình

  • 2.1. Inverted Index – MapReduce: Map

  • 2.1. Inverted Index – MapReduce: Reduce

  • 2.2. Search - MapReduce

  • 2.2. Search – MapReduce: Map

  • 2.2. Search – MapReduce: Reduce

  • 2.3. Inverted Index – Java code: Mapper class

  • 2.3. Inverted Index – Java code: Reducer class

  • 2.3. Inverted Index – Java code: Driver class

  • 2.3. Search – Java code: Mapper class

Tài liệu cùng người dùng

Tài liệu liên quan