PhraseSequenceGenerator { public List<LexicalPhrase[]> tokenSequences(JCas aJCas) throws FeaturePathException { return useCharacters ? characterSequences(aJCas) : annotationSequences(aJCas); } private  PhraseSequenceGenerator(Builder builder); List<LexicalPhrase[]> tokenSequences(JCas aJCas); static final String WHITESPACE_CHAR_REPLACEMENT; }
@Test public void testTokenSequences() throws Exception { String featurePath = Token.class.getName(); int expectedSize = 2; String expectedFirstToken = "Token1"; String expectedLastToken = "Token2"; JCas jCas = jCasWithTokens(); PhraseSequenceGenerator sequenceGenerator = new PhraseSequenceGenerator.Builder() .featurePath(featurePath) .build(); LexicalPhrase[] sequence = sequenceGenerator.tokenSequences(jCas).get(0); assertEquals(expectedSize, sequence.length); assertEquals(expectedFirstToken, sequence[0].getText()); assertEquals(expectedLastToken, sequence[sequence.length - 1].getText()); }
@Test public void testLemmaSequences() throws IOException, FeaturePathException, UIMAException { String featurePath = Token.class.getName() + "/lemma/value"; int expectedSize = 2; String expectedFirstToken = "lemma1"; String expectedLastToken = "lemma2"; JCas jCas = jCasWithLemmas(); PhraseSequenceGenerator sequenceGenerator = new PhraseSequenceGenerator.Builder() .featurePath(featurePath) .build(); LexicalPhrase[] sequence = sequenceGenerator.tokenSequences(jCas).get(0); assertEquals(expectedSize, sequence.length); assertEquals(expectedFirstToken, sequence[0].getText()); assertEquals(expectedLastToken, sequence[sequence.length - 1].getText()); }
@Test public void testGenerateSequenceFeaturePathCovering() throws FeaturePathException, UIMAException, IOException { String featurePath = Token.class.getName(); int expectedSize = 2; String expectedFirstToken = "Token1"; String expectedLastToken = "Token2"; String covering = Sentence.class.getTypeName(); JCas jCas = jCasWithSentence(); PhraseSequenceGenerator sequenceGenerator = new PhraseSequenceGenerator.Builder() .featurePath(featurePath) .lowercase(false) .coveringType(covering) .build(); List<LexicalPhrase[]> sequences = sequenceGenerator.tokenSequences(jCas); assertEquals(1, sequences.size()); LexicalPhrase[] sequence = sequences.get(0); Assert.assertEquals(expectedSize, sequence.length); Assert.assertEquals(expectedFirstToken, sequence[0].getText()); Assert.assertEquals(expectedLastToken, sequence[sequence.length - 1].getText()); }
@Test public void testGenerateSequenceStopwordsURL() throws FeaturePathException, UIMAException, IOException { int expectedSize = 2; URL stopwordsFile = this.getClass().getResource("/stopwords.txt"); String expectedFirstToken = ""; JCas jCas = jCasWithTokens(); PhraseSequenceGenerator sequenceGenerator = new PhraseSequenceGenerator.Builder() .stopwordsURL(stopwordsFile) .lowercase(false) .build(); List<LexicalPhrase[]> sequences = sequenceGenerator.tokenSequences(jCas); assertEquals(1, sequences.size()); LexicalPhrase[] sequence = sequences.get(0); Assert.assertEquals(expectedSize, sequence.length); Assert.assertEquals(expectedFirstToken, sequence[0].getText()); }
@Test public void testGenerateSequenceStopwordsFile() throws FeaturePathException, UIMAException, IOException { int expectedSize = 2; File stopwordsFile = new File("src/test/resources/stopwords.txt"); String expectedFirstToken = ""; JCas jCas = jCasWithTokens(); PhraseSequenceGenerator sequenceGenerator = new PhraseSequenceGenerator.Builder() .stopwordsFile(stopwordsFile) .lowercase(false) .build(); List<LexicalPhrase[]> sequences = sequenceGenerator.tokenSequences(jCas); assertEquals(1, sequences.size()); LexicalPhrase[] sequence = sequences.get(0); Assert.assertEquals(expectedSize, sequence.length); Assert.assertEquals(expectedFirstToken, sequence[0].getText()); }
@Test public void testGenerateSequenceStopwordsFileString() throws FeaturePathException, UIMAException, IOException { int expectedSize = 2; String stopwordsFile = "src/test/resources/stopwords.txt"; String expectedFirstToken = ""; JCas jCas = jCasWithTokens(); PhraseSequenceGenerator sequenceGenerator = new PhraseSequenceGenerator.Builder() .stopwordsFile(stopwordsFile) .lowercase(false) .build(); List<LexicalPhrase[]> sequences = sequenceGenerator.tokenSequences(jCas); assertEquals(1, sequences.size()); LexicalPhrase[] sequence = sequences.get(0); Assert.assertEquals(expectedSize, sequence.length); Assert.assertEquals(expectedFirstToken, sequence[0].getText()); }