RelationConstraint { public boolean matches(final Relation relation, final boolean symmetric) { final Entity sourceEntity = relation.getSource(); final Entity targetEntity = relation.getTarget(); final String sourceType = sourceEntity.getType().getName(); final String targetType = targetEntity.getType().getName(); final boolean relationType = type.equalsIgnoreCase(relation.getRelationshipType()) && subType.equalsIgnoreCase(relation.getRelationSubType()); if (!symmetric) { return relationType && typesEqual(sourceType, targetType); } else { return relationType && (typesEqual(sourceType, targetType) || typesEqual(targetType, sourceType)); } } RelationConstraint(
      final String type,
      final String subType,
      final String pos,
      final String source,
      final String target); String getSource(); String getTarget(); String getPos(); String getSubType(); String getType(); boolean isValid(); boolean matches(final Relation relation, final boolean symmetric); boolean matches(Interaction interaction, Collection<WordToken> words); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString();  }
@Test public void testMatches() throws UIMAException { JCas jCas = JCasSingleton.getJCasInstance(); RelationConstraint rc = new RelationConstraint("type", "subType", "pos", "source", "target"); Interaction i = new Interaction(jCas); assertFalse(rc.matches(i, Collections.emptyList())); i.setRelationshipType("type"); assertFalse(rc.matches(i, Collections.emptyList())); i.setRelationSubType("subtype"); assertTrue(rc.matches(i, Collections.emptyList())); WordToken wt1 = new WordToken(jCas); wt1.setPartOfSpeech("VERB"); WordToken wt2 = new WordToken(jCas); wt2.setPartOfSpeech("POS"); List<WordToken> wordTokens = new ArrayList<>(); wordTokens.add(wt1); assertFalse(rc.matches(i, wordTokens)); wordTokens.add(wt2); assertTrue(rc.matches(i, wordTokens)); }