MatchingConfigurationInitializer { public TypeBasedMatcherDispatcher<AnnotationFS> create() { String targetTypeNamesStr = propertyResolver .getProperty(ConfigurationKeys.KEY_MATCHING_CONFIGURATION_TARGET_TYPE); if (targetTypeNamesStr == null) { throw new IllegalStateException(String.format( "Can't create matcher because there is no property under key %s", ConfigurationKeys.KEY_MATCHING_CONFIGURATION_TARGET_TYPE)); } TypeBasedMatcherDispatcher.Builder<AnnotationFS> builder = TypeBasedMatcherDispatcher.builder(ts); List<String> targetTypeNames = Arrays.asList(StringUtils.split( targetTypeNamesStr, ",;")); for (String ttn : targetTypeNames) { Type targetType = FSTypeUtils.getType(ts, ttn, true); CompositeMatcher<AnnotationFS> m = createTargetMatcher(targetType); builder.addSubmatcher(targetType, m); } return builder.build(); } MatchingConfigurationInitializer(TypeSystem ts, PropertyResolver propertyResolver); TypeBasedMatcherDispatcher<AnnotationFS> create(); CompositeMatcher<AnnotationFS> createTargetMatcher(Type targetType); static final String MATCHER_DELIMITER_CHARS; static final String SUBMATCHER_DELIMITER_CHARS; static final String BOUNDARY_MATCHER; static final String TYPE_MATCHER; static final String PREFIX_ATTRIBUTE_MATCHER; }
@Test public void testChunkMatcher() { Map<String, Object> properties = newHashMap(); properties.put("check.targetTypes", "test.Chunk"); properties .put("check.Chunk", "checkType,feature.chunkType={primitive},feature.head={checkBoundaries},feature.dependents={ordered&ref:Word},feature.subChunks={unordered&ref:Chunk}"); properties.put("check.Word", "checkBoundaries,feature.uid={primitive}"); PropertyResolver propResolver = makePropertyResolver(properties); TypeBasedMatcherDispatcher<AnnotationFS> actualMatcher = new MatchingConfigurationInitializer(ts, propResolver).create(); Type chunkType = ts.getType("test.Chunk"); CompositeMatcher.AnnotationMatcherBuilder expectedBuilder = CompositeMatcher.builderForAnnotation(chunkType); expectedBuilder.addTypeChecker(); expectedBuilder.addPrimitiveFeatureMatcher("chunkType"); Type headRange = chunkType.getFeatureByBaseName("head").getRange(); expectedBuilder.addFSFeatureMatcher("head", CompositeMatcher.builderForAnnotation(headRange).addBoundaryMatcher().build()); Type dependentsElemRage = chunkType.getFeatureByBaseName("dependents").getRange() .getComponentType(); expectedBuilder.addFSCollectionFeatureMatcher("dependents", CompositeMatcher.builderForAnnotation(dependentsElemRage) .addBoundaryMatcher() .addPrimitiveFeatureMatcher("uid") .build(), false); expectedBuilder.addFSCollectionFeatureMatcher("subChunks", expectedBuilder, true); CompositeMatcher<AnnotationFS> expectedMatcher = expectedBuilder.build(); assertMatchersEqual( TypeBasedMatcherDispatcher.<AnnotationFS>builder(ts) .addSubmatcher(chunkType, expectedMatcher).build(), actualMatcher); }
@Test public void testDispatcher() { Map<String, Object> properties = newHashMap(); properties.put("check.targetTypes", "test.TestFirst,test.TestSecond"); properties.put("check.TestFirst", "checkType"); properties.put("check.TestSecond", "checkBoundaries"); PropertyResolver propResolver = makePropertyResolver(properties); TypeBasedMatcherDispatcher<AnnotationFS> actualMatcher = new MatchingConfigurationInitializer(ts, propResolver).create(); Type firstType = ts.getType("test.TestFirst"); Type secondType = ts.getType("test.TestSecond"); Builder<AnnotationFS> expectedBuilder = TypeBasedMatcherDispatcher.builder(ts); expectedBuilder.addSubmatcher(firstType, CompositeMatcher.builderForAnnotation(firstType).addTypeChecker().build()); expectedBuilder.addSubmatcher(secondType, CompositeMatcher.builderForAnnotation(secondType).addBoundaryMatcher().build()); assertMatchersEqual(expectedBuilder.build(), actualMatcher); }