/** * Tokenizes and indexes the file @code{file}. If @code{file} is a directory, all its files and * subdirectories are recursively processed. */ public void processFiles(File file) { TextParser parser = new TextParser(); // do not try to tokenize fs that cannot be read if (file.canRead()) { if (file.isDirectory()) { String[] fs = file.list(); // an IO error could occur if (fs != null) { for (int i = 0; i < fs.length; i++) { processFiles(new File(file, fs[i])); } } } else { try (BufferedReader br = new BufferedReader(new FileReader(file))) { String sentence; while ((sentence = br.readLine()) != null) { List<Token> tokens = parser.tokenize(sentence); if (!this.isEmptySentence(tokens)) { this.ngramModel.processTokens(tokens); this.processedSentences++; this.processedTokens += tokens.size(); } } } catch (IOException e) { e.printStackTrace(); } } } }
public void PrintGraph(TextParser p) throws IOException { // Распечатываем граф. if (Vertex == 0) p.print("У графа отсутствуют вершины."); // Если нет вершин. for (int i = 1; i <= Vertex; i++) { p.print(i + ": "); for (Iterator<Integer> j = Graph[i].iterator(); j.hasNext(); ) p.print(j.next()); p.println(); } }
public Graph(TextParser text) throws IOException { // Читаем граф с файла. Ниже пример представления графа в файле. this(text.readInt()); Edge = text.readInt(); for (int i = 0; i < Edge; i++) { int v = text.readInt(); int w = text.readInt(); addEdge(v, w); } }