public void checkForAndFindRelations(ProgressMonitorI progressMonitor, boolean sententialOnly) { String relationInstanceFileName = FileNameSchema.getRelationsFileName(Ice.selectedCorpusName); // name + "Relations"; String relationTypeFileName = FileNameSchema.getRelationTypesFileName(Ice.selectedCorpusName); // name + "Relationtypes"; File file = new File(relationTypeFileName); boolean shouldReuse = false; if (file.exists() && !file.isDirectory()) { int n = JOptionPane.showConfirmDialog( Ice.mainFrame, "Extracted patterns already exist. Show existing patterns without recomputation?", "Patterns exist", JOptionPane.YES_NO_OPTION); if (n == 0) { // reuse existing paths shouldReuse = true; // Corpus.displayTerms(relationTypeFileName, // 40, // relationTextArea, // relationFilter); // return; } } PathExtractionThread thread = new PathExtractionThread(shouldReuse, sententialOnly, textArea, progressMonitor); thread.start(); // findRelations(progressMonitor, "", relationTextArea); }
@Override public void run() { if (!shouldReuse) { RelationFinder finder = new RelationFinder( Ice.selectedCorpus.docListFileName, Ice.selectedCorpus.directory, Ice.selectedCorpus.filter, FileNameSchema.getRelationsFileName(Ice.selectedCorpusName), FileNameSchema.getRelationTypesFileName(Ice.selectedCorpusName), null, Ice.selectedCorpus.numberOfDocs, progressMonitor); finder.run(); Ice.selectedCorpus.relationTypeFileName = FileNameSchema.getRelationTypesFileName(Ice.selectedCorpus.name); Ice.selectedCorpus.relationInstanceFileName = FileNameSchema.getRelationsFileName(Ice.selectedCorpusName); } progressMonitor.setNote("Postprocessing..."); // rank paths Corpus.rankRelations( Ice.selectedCorpus.backgroundCorpus, FileNameSchema.getPatternRatioFileName( Ice.selectedCorpusName, Ice.selectedCorpus.backgroundCorpus)); DepPathMap depPathMap = DepPathMap.getInstance(); depPathMap.load(); // filter and show paths try { BufferedReader reader = new BufferedReader( new FileReader( FileNameSchema.getSortedPatternRatioFileName( Ice.selectedCorpusName, Ice.selectedCorpus.backgroundCorpus))); int k = 0; StringBuilder b = new StringBuilder(); while (true) { String line = reader.readLine(); if (line == null) break; if (sententialOnly && !line.matches(".*nsubj-1:.*:dobj.*")) { continue; } String[] parts = line.split("\\t"); if (parts.length < 2) { continue; } String repr = depPathMap.findRepr(parts[1]); if (repr == null) { continue; } b.append(parts[0].trim()).append("\t").append(repr).append("\n"); k++; if (k > SIZE_LIMIT) break; } if (progressMonitor == null || !progressMonitor.isCanceled()) { textArea.setText(b.toString()); } } catch (IOException e) { e.printStackTrace(); } progressMonitor.setProgress(progressMonitor.getMaximum()); }