IndexDBO_classes extends IndexDBO { @Override public List<String> search(final String object) { if (stopwords.contains(object.toLowerCase())) { log.debug("\t Stopword detected: |" + object + "|"); return ImmutableList.of(); } ArrayList<String> uris = Lists.newArrayList(); try { log.debug("\t start asking index..."); Query q = new FuzzyQuery(new Term(FIELD_NAME_OBJECT, object), 0); TopScoreDocCollector collector = TopScoreDocCollector.create(numberOfDocsRetrievedFromIndex); isearcher.search(q, collector); ScoreDoc[] hits = collector.topDocs().scoreDocs; for (ScoreDoc hit : hits) { Document hitDoc = isearcher.doc(hit.doc); uris.add(hitDoc.get(FIELD_NAME_SUBJECT)); } log.debug("\t finished asking index..."); } catch (Exception e) { log.error(e.getLocalizedMessage() + " -> " + object, e); } return uris; } IndexDBO_classes(); @Override List<String> search(final String object); @Override void close(); public String FIELD_NAME_SUBJECT; public String FIELD_NAME_PREDICATE; public String FIELD_NAME_OBJECT; }
@Test public void correctOutputTypeTest() { IndexDBO classes = new IndexDBO_classes(); List<String> out = classes.search("member"); Assert.assertTrue("Return for member shoudnt be empty", !out.isEmpty()); SimpleQuantityRanker ranker = new SimpleQuantityRanker(); Assert.assertTrue("Returned uri is not a dbpedia class", ranker.disambiguateOntologyIsClass(out.get(0))); }
@Test public void simpleTest() { IndexDBO_classes classes = new IndexDBO_classes(); ArrayList<String> realPresidentResultList = new ArrayList<>(); realPresidentResultList.add("http: realPresidentResultList.add("http: List<String> foundPresidentResultList = classes.search("president"); Assert.assertTrue(realPresidentResultList.equals(foundPresidentResultList)); }