@Test public void KeyphraseCandidateTest1() throws Exception { System.out.println("Only tokens. Default settings"); Set<String> expectedResults = new HashSet<String>(); expectedResults.add("example"); expectedResults.add("sentence"); expectedResults.add("funny"); expectedResults.add("second"); AnalysisEngine analysisEngine = AnalysisEngineFactory.createEngine( CandidateAnnotator.class, CandidateAnnotator.PARAM_FEATURE_PATH, Token.class.getName(), CandidateAnnotator.PARAM_RESOLVE_OVERLAPS, false); String testDocument = "example sentence funny. second example."; JCas jcas = setup(testDocument, analysisEngine); analysisEngine.process(jcas); int i=0; for (Keyphrase kc : JCasUtil.select(jcas, Keyphrase.class)) { System.out.println(kc); assertTrue(expectedResults.contains(kc.getKeyphrase())); i++; } assertEquals(5,i); }
@Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.FINE, "Entering " + this.getClass().getSimpleName()); List<Candidate> candidates = new ArrayList<Candidate>(); try { for (Entry<AnnotationFS, String> entry: FeaturePathFactory.select(jcas.getCas(), featurePath)) { candidates.add(new Candidate(entry.getValue(), entry.getKey().getBegin(), entry.getKey().getEnd())); } } catch (FeaturePathException e) { throw new AnalysisEngineProcessException(e); } List<Candidate> resolvedCandidates; if (resolveOverlaps) { resolvedCandidates = resolveOverlappingCandidates(candidates); } else { resolvedCandidates = candidates; } AnnotationIndex<Annotation> candidateIndex = jcas.getAnnotationIndex(Keyphrase.type); for (Candidate candidate : resolvedCandidates) { Keyphrase keyphrase = new Keyphrase(jcas); keyphrase.setKeyphrase(candidate.term); keyphrase.setBegin(candidate.begin); keyphrase.setEnd(candidate.end); if (!candidateIndex.contains(keyphrase)) { keyphrase.addToIndexes(jcas); } } }
CandidateAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.FINE, "Entering " + this.getClass().getSimpleName()); List<Candidate> candidates = new ArrayList<Candidate>(); try { for (Entry<AnnotationFS, String> entry: FeaturePathFactory.select(jcas.getCas(), featurePath)) { candidates.add(new Candidate(entry.getValue(), entry.getKey().getBegin(), entry.getKey().getEnd())); } } catch (FeaturePathException e) { throw new AnalysisEngineProcessException(e); } List<Candidate> resolvedCandidates; if (resolveOverlaps) { resolvedCandidates = resolveOverlappingCandidates(candidates); } else { resolvedCandidates = candidates; } AnnotationIndex<Annotation> candidateIndex = jcas.getAnnotationIndex(Keyphrase.type); for (Candidate candidate : resolvedCandidates) { Keyphrase keyphrase = new Keyphrase(jcas); keyphrase.setKeyphrase(candidate.term); keyphrase.setBegin(candidate.begin); keyphrase.setEnd(candidate.end); if (!candidateIndex.contains(keyphrase)) { keyphrase.addToIndexes(jcas); } } } }
CandidateAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.FINE, "Entering " + this.getClass().getSimpleName()); List<Candidate> candidates = new ArrayList<Candidate>(); try { for (Entry<AnnotationFS, String> entry: FeaturePathFactory.select(jcas.getCas(), featurePath)) { candidates.add(new Candidate(entry.getValue(), entry.getKey().getBegin(), entry.getKey().getEnd())); } } catch (FeaturePathException e) { throw new AnalysisEngineProcessException(e); } List<Candidate> resolvedCandidates; if (resolveOverlaps) { resolvedCandidates = resolveOverlappingCandidates(candidates); } else { resolvedCandidates = candidates; } AnnotationIndex<Annotation> candidateIndex = jcas.getAnnotationIndex(Keyphrase.type); for (Candidate candidate : resolvedCandidates) { Keyphrase keyphrase = new Keyphrase(jcas); keyphrase.setKeyphrase(candidate.term); keyphrase.setBegin(candidate.begin); keyphrase.setEnd(candidate.end); if (!candidateIndex.contains(keyphrase)) { keyphrase.addToIndexes(jcas); } } }  }
CandidateAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.FINE, "Entering " + this.getClass().getSimpleName()); List<Candidate> candidates = new ArrayList<Candidate>(); try { for (Entry<AnnotationFS, String> entry: FeaturePathFactory.select(jcas.getCas(), featurePath)) { candidates.add(new Candidate(entry.getValue(), entry.getKey().getBegin(), entry.getKey().getEnd())); } } catch (FeaturePathException e) { throw new AnalysisEngineProcessException(e); } List<Candidate> resolvedCandidates; if (resolveOverlaps) { resolvedCandidates = resolveOverlappingCandidates(candidates); } else { resolvedCandidates = candidates; } AnnotationIndex<Annotation> candidateIndex = jcas.getAnnotationIndex(Keyphrase.type); for (Candidate candidate : resolvedCandidates) { Keyphrase keyphrase = new Keyphrase(jcas); keyphrase.setKeyphrase(candidate.term); keyphrase.setBegin(candidate.begin); keyphrase.setEnd(candidate.end); if (!candidateIndex.contains(keyphrase)) { keyphrase.addToIndexes(jcas); } } }  @Override void process(JCas jcas); }
CandidateAnnotator extends JCasAnnotator_ImplBase { @Override public void process(JCas jcas) throws AnalysisEngineProcessException { getContext().getLogger().log(Level.FINE, "Entering " + this.getClass().getSimpleName()); List<Candidate> candidates = new ArrayList<Candidate>(); try { for (Entry<AnnotationFS, String> entry: FeaturePathFactory.select(jcas.getCas(), featurePath)) { candidates.add(new Candidate(entry.getValue(), entry.getKey().getBegin(), entry.getKey().getEnd())); } } catch (FeaturePathException e) { throw new AnalysisEngineProcessException(e); } List<Candidate> resolvedCandidates; if (resolveOverlaps) { resolvedCandidates = resolveOverlappingCandidates(candidates); } else { resolvedCandidates = candidates; } AnnotationIndex<Annotation> candidateIndex = jcas.getAnnotationIndex(Keyphrase.type); for (Candidate candidate : resolvedCandidates) { Keyphrase keyphrase = new Keyphrase(jcas); keyphrase.setKeyphrase(candidate.term); keyphrase.setBegin(candidate.begin); keyphrase.setEnd(candidate.end); if (!candidateIndex.contains(keyphrase)) { keyphrase.addToIndexes(jcas); } } }  @Override void process(JCas jcas); static final String PARAM_FEATURE_PATH; static final String PARAM_RESOLVE_OVERLAPS; }