QuerySegmenterDefaultImpl implements QuerySegmenter { @Override public List<TypedSegment> segment(String query) { List<TypedSegment> typedSegments = new ArrayList<TypedSegment>(); String[] segments = query.split("\\s+"); for (int i = 0; i < segments.length; i++) { for (int j = WINDOW_SIZE - 1; j >= 0; j--) { int last = i + j; if (last >= segments.length) { continue; } StringBuilder sb = new StringBuilder(); for (int k = i; k <= last; k++) { sb.append(segments[k]); if (k != last) { sb.append(" "); } } for (AbstractSegmentDictionary dictionary : dictionaries) { String segment = sb.toString(); List<? extends TypedSegment> list = dictionary.lookup(segment); if (list == null) { continue; } for (TypedSegment typedSegment : list) { typedSegment.setSegment(segment); typedSegment.setDictionaryName(dictionary.getName()); typedSegments.add(typedSegment); } } } } return typedSegments; }  @Override void addFileDictionary(String name, String filename,
      Class<? extends FileBasedSegmentDictionary> dictionaryClass); @Override void addFileDictionary(String name, String filename, String separator,
      Class<? extends FileBasedSegmentDictionary> dictionaryClass); @Override List<TypedSegment> segment(String query);  }
@Test public void test_parse() throws Exception { String query = "pizza campbell park"; List<TypedSegment> segments = segmenter.segment(query); assertEquals(1, segments.size()); TypedSegment segment = segments.get(0); assertEquals(AreaTypedSegment.TYPE, segment.getType()); assertEquals("Campbell Park", segment.getLabel()); assertEquals("campbell park", segment.getSegment()); }
@Test public void test_parse_after() throws Exception { String query = "Eagle River Valley garage"; List<TypedSegment> segments = segmenter.segment(query); assertEquals(1, segments.size()); TypedSegment segment = segments.get(0); assertEquals(AreaTypedSegment.TYPE, segment.getType()); assertEquals("Eagle River Valley", segment.getLabel()); assertEquals("Eagle River Valley", segment.getSegment()); }