id
stringlengths
36
36
text
stringlengths
1
1.25M
b3c05126-9f9c-4e4f-b8b3-abc92bc9eb55
@SuppressWarnings("unchecked") public final Group createHighscore() { try { SlidingPuzzleHighscore.readXML(); // new PuzzleHighscore("TEST", "999"); // PuzzleHighscore.writeXML(); } catch (Exception e) { e.printStackTrace(); } final int i20 = 20; final Label label = new Label("Highscores"); label.setFont(new Font("Arial", i20)); TableView<SlidingPuzzleHighscore> tableView = new TableView<SlidingPuzzleHighscore>(); tableView.setEditable(false); ObservableList<SlidingPuzzleHighscore> observableList = FXCollections .observableList(SlidingPuzzleHighscore.getPuzzleHighscores()); TableColumn<SlidingPuzzleHighscore, String> scoreColumn = new TableColumn<SlidingPuzzleHighscore, String>( "Score"); scoreColumn.setCellValueFactory( new PropertyValueFactory<SlidingPuzzleHighscore, String>( "userScore")); TableColumn<SlidingPuzzleHighscore, String> userColumn = new TableColumn<SlidingPuzzleHighscore, String>( "User"); userColumn.setCellValueFactory( new PropertyValueFactory<SlidingPuzzleHighscore, String>( "userName")); tableView.setItems(observableList); scoreColumn.setSortType(SortType.DESCENDING); tableView.getColumns().addAll(scoreColumn, userColumn); final int i5 = 5; final int i10 = 10; final VBox highscoreVBox = new VBox(); highscoreVBox.setSpacing(i5); highscoreVBox.setPadding(new Insets(i10, i10, i10, i10)); highscoreVBox.getChildren().addAll(label, tableView); Group highscoreBox = new Group(highscoreVBox); return highscoreBox; }
0afb24ef-92fd-4955-bf02-e80b4c3c6b13
public final VBox createMenu() { flow.play(); final int i20 = 20; VBox menuBox = new VBox(i20); final MenuBar menuBar = new MenuBar(); final MenuItem newMenu = MenuItemBuilder.create().text("New").build(); newMenu.setOnAction(new EventHandler<ActionEvent>() { public void handle(final ActionEvent t) { newGame(); } }); final MenuItem mergeMenu = MenuItemBuilder.create().text("Merge") .build(); mergeMenu.setOnAction(new EventHandler<ActionEvent>() { public void handle(final ActionEvent t) { newGame(); mergePuzzlePieces(gameBoard, SlidingPuzzlePiece.getPuzzlePiece()); flow.playFromStart(); } }); final MenuItem resolveMenu = MenuItemBuilder.create().text("Resolve") .build(); resolveMenu.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { for (final SlidingPuzzlePiece puzzlePiece : SlidingPuzzlePiece .getPuzzlePiece()) { puzzlePiece.setInactive(); flow.getKeyFrames().add( new KeyFrame(Duration.seconds(1), new KeyValue( puzzlePiece.translateXProperty(), 0), new KeyValue(puzzlePiece .translateYProperty(), 0))); } flow.playFromStart(); } }); MenuItem easyLevel = MenuItemBuilder.create().text("Easy").build(); easyLevel.setOnAction(new EventHandler<ActionEvent>() { public void handle(final ActionEvent t) { final int i100 = 100; final int i10 = 10; SlidingPuzzlePiece.setPuzzleSize(i100); setMergeCount((gameBoard.getCols() * gameBoard.getRows()) * i10); newGame(); } }); MenuItem normalLevel = MenuItemBuilder.create().text("Normal").build(); normalLevel.setOnAction(new EventHandler<ActionEvent>() { public void handle(final ActionEvent t) { final int i75 = 75; final int i50 = 50; SlidingPuzzlePiece.setPuzzleSize(i75); setMergeCount((gameBoard.getCols() * gameBoard.getRows()) * i50); newGame(); } }); MenuItem hardLevel = MenuItemBuilder.create().text("Hard").build(); hardLevel.setOnAction(new EventHandler<ActionEvent>() { public void handle(final ActionEvent t) { final int i50 = 50; final int i100 = 100; SlidingPuzzlePiece.setPuzzleSize(i50); setMergeCount((gameBoard.getCols() * gameBoard.getRows()) * i100); newGame(); } }); MenuItem harderLevel = MenuItemBuilder.create().text("Harder").build(); harderLevel.setOnAction(new EventHandler<ActionEvent>() { public void handle(final ActionEvent t) { final int i25 = 25; final int i200 = 200; SlidingPuzzlePiece.setPuzzleSize(i25); setMergeCount((gameBoard.getCols() * gameBoard.getRows()) * i200); newGame(); } }); final Menu levelMenu = MenuBuilder.create().text("GameLevel") .items(easyLevel, normalLevel, hardLevel, harderLevel).build(); final MenuItem highscoreMenu = MenuItemBuilder.create() .text("Highscore").build(); highscoreMenu.setOnAction(new EventHandler<ActionEvent>() { public void handle(final ActionEvent t) { Stage stage = new Stage(); Scene highscore = new Scene(createHighscore()); stage.setTitle("Sliding Puzzle - Highscores"); stage.sizeToScene(); stage.setScene(highscore); stage.toFront(); stage.show(); thisStage = stage; thisStage.centerOnScreen(); } }); Menu menuGame = MenuBuilder.create().text("Game") .items(newMenu, mergeMenu, resolveMenu).build(); Menu menuOptions = MenuBuilder.create().text("Options") .items(levelMenu, highscoreMenu).build(); menuBar.getMenus().addAll(menuGame, menuOptions); menuBox.getChildren().addAll(menuBar); menuBar.isCache(); return menuBox; }
d47fed48-3ca8-4149-8891-5cf87315dc57
public void handle(final ActionEvent t) { newGame(); }
2ea3ff62-e0af-48d4-b0bc-c43c868b8871
public void handle(final ActionEvent t) { newGame(); mergePuzzlePieces(gameBoard, SlidingPuzzlePiece.getPuzzlePiece()); flow.playFromStart(); }
e4a3fee2-2410-415d-b62d-560b35036023
@Override public void handle(final ActionEvent actionEvent) { for (final SlidingPuzzlePiece puzzlePiece : SlidingPuzzlePiece .getPuzzlePiece()) { puzzlePiece.setInactive(); flow.getKeyFrames().add( new KeyFrame(Duration.seconds(1), new KeyValue( puzzlePiece.translateXProperty(), 0), new KeyValue(puzzlePiece .translateYProperty(), 0))); } flow.playFromStart(); }
62d09f91-412b-4006-914b-59f7434ecc27
public void handle(final ActionEvent t) { final int i100 = 100; final int i10 = 10; SlidingPuzzlePiece.setPuzzleSize(i100); setMergeCount((gameBoard.getCols() * gameBoard.getRows()) * i10); newGame(); }
ca393846-3598-4ae8-9960-820b1817a17a
public void handle(final ActionEvent t) { final int i75 = 75; final int i50 = 50; SlidingPuzzlePiece.setPuzzleSize(i75); setMergeCount((gameBoard.getCols() * gameBoard.getRows()) * i50); newGame(); }
37aa5e83-754f-4ea7-bf99-3fee3d5edbee
public void handle(final ActionEvent t) { final int i50 = 50; final int i100 = 100; SlidingPuzzlePiece.setPuzzleSize(i50); setMergeCount((gameBoard.getCols() * gameBoard.getRows()) * i100); newGame(); }
7e3a999a-cf89-4d36-a58b-62f451980ed9
public void handle(final ActionEvent t) { final int i25 = 25; final int i200 = 200; SlidingPuzzlePiece.setPuzzleSize(i25); setMergeCount((gameBoard.getCols() * gameBoard.getRows()) * i200); newGame(); }
64416c79-3d28-4b88-8354-a48341b6a520
public void handle(final ActionEvent t) { Stage stage = new Stage(); Scene highscore = new Scene(createHighscore()); stage.setTitle("Sliding Puzzle - Highscores"); stage.sizeToScene(); stage.setScene(highscore); stage.toFront(); stage.show(); thisStage = stage; thisStage.centerOnScreen(); }
a923176d-6051-454b-888c-03cd65814e6b
private void init(final Stage primaryStage) { thisStage = primaryStage; thisStage.setTitle("Sliding Puzzle"); StackPane sPane = new StackPane(); Label label = new Label("Name: "); final TextField nameField = new TextField(); final Button setNameField = new Button("OK"); final int i5 = 5; final int i10 = 10; final int i20 = 20; final int i100 = 100; nameField.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(final KeyEvent event) { if (event.getCode() == KeyCode.ENTER) { setNameField.fire(); } } }); setNameField.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(final ActionEvent actionEvent) { if (nameField.getText() != "" && nameField.getText() != null) { userName = nameField.getText(); } SlidingPuzzlePiece.setPuzzleSize(i100); newGame(); } }); VBox welcomeBox = new VBox(i5); Text welcomeText = new Text(i100, i100, "Welcome to the Sliding Puzzle\n\nWhats your name?\n"); welcomeText.setFont(new Font(i20)); welcomeText.setTextAlignment(TextAlignment.CENTER); welcomeBox.getChildren().add(welcomeText); welcomeBox.setPadding(new Insets(i10, i10, i10, i10)); HBox displayBox = new HBox(i5); displayBox.getChildren().addAll(label, nameField, setNameField); displayBox.setAlignment(Pos.CENTER); welcomeBox.getChildren().add(displayBox); sPane.getChildren().add(welcomeBox); thisStage.centerOnScreen(); thisStage.toFront(); thisStage.setScene(new Scene(sPane)); thisStage.show(); }
555276e2-ec31-4c4d-bf68-07c4f68c2a21
@Override public void handle(final KeyEvent event) { if (event.getCode() == KeyCode.ENTER) { setNameField.fire(); } }
800d52d1-4962-467e-98ee-42f0a3681507
@Override public void handle(final ActionEvent actionEvent) { if (nameField.getText() != "" && nameField.getText() != null) { userName = nameField.getText(); } SlidingPuzzlePiece.setPuzzleSize(i100); newGame(); }
650944c3-1d5b-42fa-a36d-65df7b254f7d
public final void mergePuzzlePieces(final SlidingPuzzleBoard newGameBoard, final List<SlidingPuzzlePiece> puzzlePiece) { for (int i = 0; i <= mergeProcedures; i++) { SlidingPuzzlePiece firstPiece = SlidingPuzzlePiece.getPuzzlePiece() .get(randomDigit(0, SlidingPuzzlePiece.getPuzzlePiece() .size())); SlidingPuzzleField firstField = firstPiece.getField(); SlidingPuzzlePiece secondPiece = SlidingPuzzlePiece .getPuzzlePiece().get( randomDigit(0, SlidingPuzzlePiece.getPuzzlePiece() .size())); SlidingPuzzleField secondField = secondPiece.getField(); int firstFromX = firstField.getFieldCol(); int firstFromY = firstField.getFieldRow(); int firstToX = secondField.getFieldCol(); int firstToY = secondField.getFieldRow(); System.out.println("switching " + firstFromX + "-" + firstFromY + " with " + firstToX + "-" + firstToY); double firstFreeX = secondField.getFieldCoordX(); double firstFreeY = secondField.getFieldCoordY(); double secondFreeX = firstField.getFieldCoordX(); double secondFreeY = firstField.getFieldCoordY(); double firstShuffleX = (firstFreeX - firstField.getFieldCoordX()) + firstPiece.getTranslateX(); double firstShuffleY = (firstFreeY - firstField.getFieldCoordY()) + firstPiece.getTranslateY(); double secondShuffleX = (secondFreeX - secondField.getFieldCoordX()) + secondPiece.getTranslateX(); double secondShuffleY = (secondFreeY - secondField.getFieldCoordY()) + secondPiece.getTranslateY(); firstPiece.setTranslateX(firstShuffleX); firstPiece.setTranslateY(firstShuffleY); secondPiece.setTranslateX(secondShuffleX); secondPiece.setTranslateY(secondShuffleY); secondField.setFieldCoordX(firstField.getFieldCoordX()); secondField.setFieldCoordY(firstField.getFieldCoordY()); secondField.setFieldCol(firstFromX); secondField.setFieldRow(firstFromY); firstField.setFieldCoordX(firstFreeX); firstField.setFieldCoordY(firstFreeY); firstField.setFieldCol(firstToX); firstField.setFieldRow(firstToY); } System.out.println("merged.."); }
12ee0730-37f8-406d-aea3-ee5917df9019
public final void newGame() { if (SlidingPuzzlePiece.getPuzzlePiece() != null) { SlidingPuzzlePiece.getPuzzlePiece().clear(); } Group newGroup = new Group(); newGroup = createGameBoard(); thisStage.setTitle("Sliding Puzzle - " + userName); thisStage.sizeToScene(); thisStage.centerOnScreen(); thisStage.toFront(); thisStage.setScene(new Scene(newGroup)); thisStage.show(); moveCount = 0; flow.play(); }
d11218c3-3d7b-4aa5-b930-85129e8d5916
@Override public final void start(final Stage stage) throws Exception { init(stage); stage.show(); }
77c43040-4c72-4878-abae-7acb1dfe412d
public TinyReception() { }
5dd00ed2-f217-4c8a-acfb-5402bcadf95c
public String getName() { return name; }
3a9bb782-3c75-4ba8-9ba6-4d594f31c1f9
public void setName(String name) { this.name = name; }
d5c5312e-faab-4307-9810-d9aed3ef1d42
public static List<Book> getBookList() { return bookList; }
c6dc3e2c-c42b-4a3c-b5a0-cf7f7a6b6143
public static Book getBook(String bookId) { for (Book book : bookList) { if (book.getId().equals(bookId)) return book; } return null; }
50d46cf2-476c-436a-a3b3-7f8e6fc62325
public Book(String id, String name, String alias, String image, String url, String desc, String author) { super(); this.id = id; this.name = name; this.alias = alias; this.image = image; this.url = url; this.desc = desc; this.author = author; }
454864cd-771b-4cc7-9309-b3abeed49f88
public String getId() { return id; }
c71c64de-92bb-448f-8cde-8f93c5284100
public void setId(String id) { this.id = id; }
69bea236-1ca5-40b7-b30e-16a601bc39a7
public String getName() { return name; }
d6d774a4-5951-4486-bd81-51730a17f3e6
public void setName(String name) { this.name = name; }
8281e8ba-e623-4a26-b8fb-fa738d3eb321
public String getImage() { return image; }
17980e52-af70-489f-ac6f-8f64e2a69d98
public void setImage(String image) { this.image = image; }
720e8af1-27f0-442b-9250-b16258437ed7
public String getUrl() { return url; }
f3a666c5-c6e0-4627-ac2c-9e45c5536bef
public void setUrl(String url) { this.url = url; }
f6523a09-10d3-4c93-ae7d-2903931c33f3
public String getDesc() { return desc; }
21c9d471-560f-47d0-8d02-a9bcacf6f187
public void setDesc(String desc) { this.desc = desc; }
9d74d7c3-d449-476d-bb66-4cc212dfedbe
public String getAuthor() { return author; }
77fb4e4d-ffbc-4731-81aa-9b0df5a346db
public void setAuthor(String author) { this.author = author; }
2c502275-0778-47b3-940a-ef00877b2647
@Override public String toString() { return id + "-" + name; }
1a587391-b983-4ebc-9b8c-3920c161147b
public String getAlias() { return alias; }
cc3d5aa7-f75b-46f9-b6d4-1cdda5d60ed6
public void setAlias(String alias) { this.alias = alias; }
80e9f859-eb9d-4a1a-a337-134541cbce9d
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj == null) return false; if (obj.getClass() != getClass()) return false; return ((Book) obj).id.equals(id); }
913bab56-3994-417b-be90-5ebee3ad5b15
@Override public int hashCode() { return id.hashCode() * 31; }
8134e1c5-cece-40e3-81ff-2b885274ec45
public Book getB() { return b; }
7af28b75-cf9e-4b84-a4af-c7cacd0dbe7c
public void insert() { }
48270ccf-1ffd-458c-aeb5-3b78791e649e
public String edit() { String bookId = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("bookId"); b = TinyBooks.getBook(bookId); return "book"; }
bc2eb1e6-5dfe-427f-a3fa-ff70e1fbe566
public void remove() { }
cbcc2410-c2c1-4fbb-a371-5b0ba76dbd88
public BookListBean() { books = TinyBooks.getBookList(); }
985a6d39-6726-426e-8b7c-57d794155ed2
public List<Book> getBooks() { return books; }
6f0681cf-9594-4eba-a8e7-8ee44045c17e
public List<Book> getBorrowbooks() { return borrowbooks; }
2ab65094-ef65-401b-9a2b-b1cffc9038a4
public void borrow(DropEvent event) { Book dragged = (Book) event.getDragValue(); if (borrowbooks == null) borrowbooks = new ArrayList<Book>(); borrowbooks.add(dragged); }
57ea9a78-2129-4575-9a26-7468fb008349
public ValueComparator(Map<String, Double> base) { this.base = base; }
2ef92cc1-9fe9-4cb8-ac1c-275a2d4315c4
public int compare(String a, String b) { if(base.get(a) >= base.get(b)) { return -1; } else { return 1; } }
0e6b433d-7f9a-453a-9f28-9aa0e6e4c866
public InfoRetrieval() throws Exception { conf = new Configuration(); fs = FileSystem.get(conf); }
683e0262-85b8-479c-bf56-48c5a1cea059
private void searchDoc(String file_name) throws Exception { Path file_name_path = new Path(src_path + "/" + file_name); FSDataInputStream in = fs.open(file_name_path); BufferedReader br_in = new BufferedReader(new InputStreamReader(in)); String message_in; int line_num = 0; while( (message_in = br_in.readLine()) != null) { line_num++; for(String search_word : search_words) { String compared_message_in = new String(message_in); if(ignore_case_flag == true) { compared_message_in = compared_message_in.toLowerCase(); search_word = search_word.toLowerCase(); } String pattern_string = new String("\\b(" + search_word +")\\b"); Pattern pattern = Pattern.compile(pattern_string); Matcher matcher = pattern.matcher(compared_message_in); // if(message_in.indexOf(search_word) != -1) if(matcher.find()) { System.out.println("line" + line_num + ":" + message_in); // System.out.println("line" + line_num + ":" + matcher.group(1)); } } } }
085cb327-f8da-40fe-9af2-dde722bb5a9f
private void show(int max_doc_num) throws Exception { if(doc_weight_map.size() != 0) { System.out.println(doc_weight_map.size() + " acticles contain the word(s)!"); ValueComparator value_compr = new ValueComparator(doc_weight_map); TreeMap<String, Double> sorted_map = new TreeMap<String, Double>(value_compr); sorted_map.putAll(doc_weight_map); int doc_num = 0; for(String file_name: sorted_map.keySet()) { if(doc_num < max_doc_num) { Double tf_idf = doc_weight_map.get(file_name); System.out.println(file_name + ": score=" + tf_idf); searchDoc(file_name); } doc_num++; } } else { System.out.println("the word(s) cannot be found!"); } }
ec16000d-278d-4482-b793-f94bf69c9a39
public HashMap<String, Double> searchSingleWord(String search_word) throws Exception { HashMap<String, Double> doc_weight_map = new HashMap<String, Double>(); Path src_doc_path = new Path(src_path); FileStatus[] src_doc_list = fs.listStatus(src_doc_path); final int doc_num = src_doc_list.length; Path index_file_path = new Path(index_file_name); FSDataInputStream in = fs.open(index_file_path); BufferedReader br_in = new BufferedReader(new InputStreamReader(in)); String message_in; while( (message_in = br_in.readLine()) != null) { String[] word_and_info = message_in.split("\t"); String word = word_and_info[0]; if(ignore_case_flag == true) { word = word.toLowerCase(); search_word = search_word.toLowerCase(); } if(word.equals(search_word)) { String[] word_info = word_and_info[1].split(" "); int doc_freq = Integer.parseInt(word_info[1].trim()); String[] doc_and_info = word_info[2].split("\\]"); for( int i=0; i<doc_freq; i++ ) { String[] doc_and_info_token = doc_and_info[i].split("\\["); String file_name = doc_and_info_token[0]; String[] info_token = doc_and_info_token[1].split(":"); int term_freq = Integer.parseInt(info_token[0]); double tf_idf = term_freq * Math.log10(1.0 * doc_num / doc_freq); /* System.out.println(term_freq); System.out.println(doc_num); System.out.println(doc_freq); */ doc_weight_map.put(file_name, new Double(tf_idf)); } } } in.close(); return doc_weight_map; }
b8fe80ad-2dd1-4807-8169-59b2279d7bfd
public void search() throws Exception { doc_weight_map = new HashMap<String, Double>(); Set<String> doc_weight_set = new HashSet<String>( doc_weight_map.keySet() ); if(search_command.contains("-i")) { ignore_case_flag = true; search_command = search_command.replace("-i","").trim(); } search_words = search_command.split(" "); for(String search_word : search_words) { if( search_word.equals("-o") ) { op = SetOperation.Union; } else if( search_word.equals("-a") ) { op = SetOperation.Intersection; } // if( !search_word.equals("-o") && !search_word.equals("-a") ) else { HashMap<String, Double> result_map = searchSingleWord(search_word); Set<String> result_set = result_map.keySet(); if( op == SetOperation.Union ) { doc_weight_set.addAll(result_set); } if( op == SetOperation.Intersection ) { doc_weight_set.retainAll(result_set); } for(String file_name: doc_weight_set) { Double tf_idf = doc_weight_map.get(file_name); Double result_tf_idf = result_map.get(file_name); if(tf_idf == null) { tf_idf = result_map.get(file_name); doc_weight_map.put(file_name, tf_idf); } else if(result_tf_idf != null) { Double new_tf_idf = tf_idf + result_tf_idf; doc_weight_map.remove(file_name); doc_weight_map.put(file_name, new_tf_idf); } } if( op == SetOperation.Intersection ) { Set<String> file_name_set = doc_weight_map.keySet(); Iterator<String> it = file_name_set.iterator(); /* for(String file_name: doc_weight_map.keySet() ) { if( !doc_weight_set.contains(file_name) ) { doc_weight_map.remove(file_name); } } */ while(it.hasNext()) { String file_name = it.next(); if( !doc_weight_set.contains(file_name) ) { it.remove(); } } } } } }
90c3601e-c419-4e43-a32d-760fcd64f944
public static void main(String [] args) throws Exception { InfoRetrieval info_retrieval = new InfoRetrieval(); info_retrieval.src_path = args[0]; info_retrieval.index_file_name = args[1]; // info_retrieval.search_word = args[2]; while(true) { System.out.println("Enter the word you want to search:"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); // info_retrieval.search_word = br.readLine(); info_retrieval.search_command = br.readLine(); info_retrieval.search(); /* for(String search_word : search_words) { info_retrieval.search(search_word); } */ info_retrieval.show(10); } }
ddc5dc09-5caf-4c3c-aff8-6f44231866b7
public WordInfo () {}
ead94a73-f7da-42c5-818c-8793e1d34388
public WordInfo (WordInfo other) { this.line_offset_set = other.line_offset_set; }
f86efe3d-731b-4b9c-a1d1-31f3890bca12
public WordInfo (HashSet<String> line_offset_set) { this.line_offset_set = line_offset_set; }
5d40fe85-f9b3-4e54-96ca-420a53ec7a9c
public WordInfo (String line_offset) { this.line_offset_set.add(line_offset); }
0fbbab2a-4af6-4248-a8d8-e03d63c1225e
public HashSet<String> getLineOffsetSet() { return line_offset_set; }
ba28f235-e71c-45e1-830a-6542be63441a
public void insertLineOffset(String line_offset) { this.line_offset_set.add(line_offset); }
045c39b1-1318-4c41-9db9-5619faa4ce39
public void merge(HashSet<String> new_line_offset_set) { this.line_offset_set.addAll(new_line_offset_set); }
383d9172-3f39-44e8-860a-dd5a2c2833f8
public void merge(WordInfo new_word_info) { this.line_offset_set.addAll(new_word_info.line_offset_set); //test this.line_offset_set.add("test"); }
c1851562-cafe-42f4-a624-42f4c9c9806f
private int getLineOffsetNum() { return line_offset_set.size(); }
8ffb5cf3-6493-42a7-96dd-e7b27cfaeda9
public void write(DataOutput out) throws IOException { Iterator<String> it = line_offset_set.iterator(); while( it.hasNext() ) { String line_offset = it.next(); // new Text(line_offset).write(out); out.writeUTF(line_offset); } }
cb9b5ad9-6412-4c70-bc73-4d8b80268685
public void readFields(DataInput in) throws IOException { Iterator<String> it = line_offset_set.iterator(); while( it.hasNext() ) { String line_offset = it.next(); new Text(line_offset).readFields(in); // line_offset = in.readUTF(); } }
36b9a062-2421-4e03-964a-6023260b9c24
public String toString() { // term freq: line_offset_set.size() String word_info_string = " " + getLineOffsetNum() + " ["; SortedSet<String> line_offsets = new TreeSet<String>(line_offset_set); for(String line_offset : line_offsets) { word_info_string += ( line_offset + "," ); } word_info_string += "] "; return word_info_string; }
13a66151-ce45-46d9-a72e-f20e6aa514ea
public static void main(String[] args) throws Exception { JobConf conf = new JobConf(InvertedIndex.class); conf.setJobName("InvertedIndex"); conf.setInputFormat(TextInputFormat.class); conf.setOutputFormat(TextOutputFormat.class); conf.setMapOutputKeyClass(InvertedIndexKey.class); // conf.setMapOutputValueClass(IntWritable.class); // conf.setMapOutputValueClass(WordInfo.class); conf.setMapOutputValueClass(Text.class); conf.setOutputKeyClass(Text.class); conf.setOutputValueClass(InvertedIndexValue.class); conf.setNumReduceTasks(1); conf.setMapperClass(InvertedIndexMapper.class); conf.setCombinerClass(InvertedIndexCombiner.class); conf.setReducerClass(InvertedIndexReducer.class); conf.setPartitionerClass(InvertedIndexPartitioner.class); conf.setOutputKeyComparatorClass(KeyComparator.class); conf.setOutputValueGroupingComparator(GroupComparator.class); FileInputFormat.setInputPaths(conf, new Path(args[0])); FileOutputFormat.setOutputPath(conf, new Path(args[1])); JobClient.runJob(conf); }
9d2bca0c-d07b-4df2-b5d2-3a84152c6239
@Override public void reduce(InvertedIndexKey key, Iterator<Text> values, OutputCollector<Text, InvertedIndexValue> output, Reporter reporter) throws IOException { doc_freq = 0; line_offset = ""; word_info = ""; while(values.hasNext()) { String[] token = values.next().toString().split(seperator); doc_freq += Integer.parseInt(token[0]); if( !line_offset.equals("") ) { line_offset += ","; } line_offset += token[1]; } word_info = doc_freq + seperator + line_offset; if( word != null && !key.getWord().equals(word) ) { output.collect(new Text(word), new InvertedIndexValue(map)); map = new HashMap<String, String>(); } word = key.getWord(); map.put( key.getFileName(), word_info ); }
8cc2140e-71e2-42e3-ad23-4b1a9f33a70c
public InvertedIndexValue() {}
43fd74e3-2fa2-4dc5-9d84-a8e9c836b056
public InvertedIndexValue(HashMap<String, String> map) { this.map = map; }
86bad571-bb5b-4f3b-96e4-0fa84e61e29e
public void insert(String file_name, String word_info) { this.map.put(file_name, word_info); }
1cc08db4-1a53-4ac7-9789-9426d9a96021
private String getString(String file_name) { return map.get(file_name); }
e9c3acf8-917f-4445-a117-0a755bbf5c6e
public void write(DataOutput out) throws IOException { Iterator<String> it = map.keySet().iterator(); while( it.hasNext() ) { String file_name = it.next(); /* Integer term_freq = getTermFreq(file_name); new Text(file_name).write(out); new IntWritable(term_freq).write(out); */ String word_info = getString(file_name); new Text(file_name).write(out); new Text(word_info).write(out); } }
cfb3fdde-d646-42ef-b494-6a1926a90471
public void readFields(DataInput in) throws IOException { Iterator<String> it = map.keySet().iterator(); while( it.hasNext() ) { String file_name = it.next(); /* Integer term_freq = getTermFreq(file_name); new Text(file_name).readFields(in); new IntWritable(term_freq).readFields(in); */ String word_info = getString(file_name); new Text(file_name).readFields(in); new Text(word_info).readFields(in); } }
004b5412-8209-4d80-9b41-06c7dd745ac9
public String toString() { // document freq: map.size() String value_string = " " + map.size() + " "; SortedSet<String> keys = new TreeSet<String>(map.keySet()); for(String file_name: keys) { String word_info = getString(file_name); value_string += ( file_name + "[" + word_info + "]" ); } return value_string; }
d5bc5741-fff8-4fb0-bf9f-be44bc0e7041
public InvertedIndexKey() {}
98825fcc-08f8-4738-9132-8aa8de95f6e0
public InvertedIndexKey(String word, String file_name) { this.word = word; this.file_name = file_name; }
2e9f766a-6e9e-419b-9da2-8a1c995c081e
public InvertedIndexKey(InvertedIndexKey other) { this.word = other.word; this.file_name = other.file_name; }
5d0a8175-9bcb-47f9-b9b5-6abb9722dd50
public String getWord() { return word; }
b9c94368-6ceb-4660-842a-06735169f23a
public String getFileName() { return file_name; }
b1e7214c-010c-4f04-9249-568a14773455
public void write(DataOutput out) throws IOException { out.writeUTF(word); out.writeUTF(file_name); }
7dd94126-ac49-4704-aaef-6760eb35888e
public void readFields(DataInput in) throws IOException { word = in.readUTF(); file_name = in.readUTF(); }
03385fbc-2f86-4095-8374-2960eb50669c
public String toString() { return word + " " + file_name; }
db6feffb-779a-4934-ac5a-33910852bf7c
public int compareTo(InvertedIndexKey other) { String my_word = getWord(); String other_word = other.getWord(); String my_file_name = getFileName(); String other_file_name = other.getFileName(); if(my_word.compareTo(other_word) == 0) { return my_file_name.compareTo(other_file_name); } else { return my_word.compareTo(other_word); } }
cd781595-e095-46e9-b5fb-e449922af927
public boolean equals(Object o) { if (!(o instanceof InvertedIndexKey)) { return false; } InvertedIndexKey other = (InvertedIndexKey)o; return this.word.equals(other.word) && this.file_name.equals(other.file_name); }
cec06808-cee3-4f6b-aaf7-c5fab9243d98
public int hashCode() { return word.hashCode() ^ file_name.hashCode(); }
dcdc45d1-5331-416c-ba0c-56227a33b6bb
@Override public void reduce(InvertedIndexKey key, Iterator<Text> values, OutputCollector<InvertedIndexKey, Text> output, Reporter reporter) throws IOException { doc_freq = 0; line_offset = ""; word_info = ""; while(values.hasNext()) { String[] token = values.next().toString().split(seperator); doc_freq += Integer.parseInt(token[0]); if( !line_offset.equals("") ) { line_offset += ","; } line_offset += token[1]; } word_info = doc_freq + seperator + line_offset; output.collect(key, new Text(word_info)); }
c109f7a5-f069-48c5-8892-ec6c95de2ac4
public int getPartition(InvertedIndexKey key, Text value, int numPart) { return (key.getWord().hashCode()) % numPart; }
9e2440e5-019a-45d0-8275-932564304084
public void configure(JobConf arg0) {}
1b66b89b-bd06-48f4-8661-d983dc16fa05
@Override public void map(LongWritable key, Text value, OutputCollector<InvertedIndexKey, Text> output, Reporter reporter) throws IOException { String line = value.toString(); line_offset = key.toString(); word_info = doc_freq + seperator + line_offset; FileSplit split = (FileSplit)(reporter.getInputSplit()); String file_name = split.getPath().getName(); // need to implement a tokenizer // maybe regex StringTokenizer itr = new StringTokenizer(line, " \t\n\r\f<>{}()[]&*#,.:;<>+-?///!'/0123456789"); while(itr.hasMoreTokens()) { String token = itr.nextToken().trim(); inverded_index_key = new InvertedIndexKey(token, file_name); output.collect(inverded_index_key, new Text(word_info)); } }
dcebfa23-cc6a-45a2-9b64-ebb594fc76ed
public WebConfig() { super(); }
cba8882b-ef4c-4d9d-be3f-6a855b24ff59
public SpringSecurityConfig() { super(); }
02db1aa1-d00a-4a87-813d-ac2a4e46b99c
public CustomerDetailService() { super(); }
d0e57e6b-4cd8-4f49-9afc-4c4d8ed141a3
@RequestMapping(value = "/{id}", method = RequestMethod.GET, consumes = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody public CustomerDetails findById(@PathVariable("id") final Long id, final UriComponentsBuilder uriBuilder, final HttpServletResponse response) { return new CustomerDetails(randomAlphabetic(6)); }
1cc74af6-ce77-4b8a-a1b3-233079578787
@RequestMapping(method = RequestMethod.GET, consumes = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody public List<CustomerDetails> findAll() { return Lists.newArrayList(new CustomerDetails(randomAlphabetic(6))); }
ffbcf4cb-92b7-4a99-8d1d-5306342e27bb
public CustomerDetails() { super(); }
20e1342d-d93f-4234-a01a-9a8d614247a2
public CustomerDetails(final String name) { super(); this.name = name; }
314c3a9a-b27d-4966-a89a-0f0151befb10
public long getId() { return id; }
bcce0b8e-0063-4a96-ae5c-d3616f1e798c
public void setId(final long id) { this.id = id; }