IndexDBO_properties extends IndexDBO { @Override public List<String> search(final String object) { if (stopwords.contains(object.toLowerCase())) { log.debug("\t Stopword detected: |" + object + "|"); System.out.println("returning immutable empty"); return ImmutableList.of(); } ArrayList<String> uris = Lists.newArrayList(); try { log.debug("\t start asking index for |" + object + "|"); 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); log.debug(object + "->" + hitDoc.get(FIELD_NAME_SUBJECT) + ", " + hitDoc.get(FIELD_NAME_OBJECT)); 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_properties(); @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 properties = new IndexDBO_properties(); List<String> out = properties.search("member"); Assert.assertTrue("Return for member shoudnt be empty", !out.isEmpty()); SimpleQuantityRanker ranker = new SimpleQuantityRanker(); Assert.assertTrue("Returned uri is not a dbpedia property: |" + out.get(0) + "|", ranker.disambiguateOntologyIsProperty(out.get(0))); }
@Test public void simpleTest() { IndexDBO properties = new IndexDBO_properties(); String spouse = "http: Assert.assertTrue(properties.search("husband").get(0).equals(spouse)); Assert.assertTrue(properties.search("wife").get(0).equals(spouse)); }