### Question:
SimplePatternMatcher { public Collection<Relation> match(Sentence sentence, ParsedWikiDocument doc) { List<Relation> result = new ArrayList<>(); List<Match<Word>> identifierMatches = patterns.get(0).find(sentence.getWords()); if (identifierMatches.size() > 0) { List<Match<Word>> definiensMatches = patterns.get(1).find(sentence.getWords()); if (definiensMatches.size() > 0) { for (Match<Word> identifier : identifierMatches) { for (Match<Word> definiens : definiensMatches) { if (definiens.getVariable(DEFINITION).getWord().length() >= 3) { Relation relation = new Relation(); relation.setIdentifier(identifier.getVariable(IDENTIFIER).getWord()); relation.setDefinition(definiens.getVariable(DEFINITION), doc); Word definiensWord = sentence.getWords().remove(definiens.matchedFrom()); Word cleanDefiniensWord = new Word(relation.getDefinition(), definiensWord.getPosTag()); sentence.getWords().add(definiens.matchedFrom(), cleanDefiniensWord); relation.setSentence(sentence); relation.setIdentifierPosition(identifier.matchedFrom()); relation.setWordPosition(definiens.matchedFrom()); result.add(relation); } } } } } return result; } private  SimplePatternMatcher(List<Pattern<Word>> patterns); Collection<Relation> match(Sentence sentence, ParsedWikiDocument doc); static SimplePatternMatcher generatePatterns(Set<String> identifiers); static final String IDENTIFIER; static final String DEFINITION; }### Answer:
@Test public void testMatch() { List<Word> words = new ArrayList<>(); words.add(new Word("bar", "NN")); words.add(new Word("a", "ID")); words.add(new Word("foo", "VB")); words.add(new Word("car bartz", "LNK")); words.add(new Word("at", "NNP")); Sentence s = new Sentence(words, identifiers, null); Collection<Relation> relations = simplePatternMatcher.match(s, doc); Assert.assertEquals(2, relations.size()); List<Relation> sorted = new ArrayList<>(relations); Collections.sort(sorted, (r1, r2) -> r1.getDefinition().compareTo(r2.getDefinition())); Assert.assertEquals("a", sorted.get(0).getIdentifier()); Assert.assertEquals("[[car bartz]]", sorted.get(0).getDefinition()); Assert.assertEquals(1, sorted.get(0).getIdentifierPosition()); Assert.assertEquals(3, sorted.get(0).getWordPosition()); Assert.assertEquals("a", sorted.get(1).getIdentifier()); Assert.assertEquals("bar", sorted.get(1).getDefinition()); Assert.assertEquals(1, sorted.get(1).getIdentifierPosition()); Assert.assertEquals(0, sorted.get(1).getWordPosition()); }