DBpediaIndex { private void index() { try { Model dbpedia = ModelFactory.createDefaultModel(); dbpedia.read(this.getClass().getClassLoader().getResource("dbpedia_2015-10.owl").getPath(), "RDF/XML"); StmtIterator stmts = dbpedia.listStatements(null, RDFS.label, (RDFNode) null); while (stmts.hasNext()) { final Statement stmt = stmts.next(); RDFNode label = stmt.getObject(); if (label.asLiteral().getLanguage().equals("en")) { addDocumentToIndex(stmt.getSubject(), "rdfs:label", label.asLiteral().getString()); NodeIterator comment = dbpedia.listObjectsOfProperty(stmt.getSubject(), RDFS.comment); while (comment.hasNext()) { RDFNode next = comment.next(); if (next.asLiteral().getLanguage().equals("en")) { addDocumentToIndex(stmt.getSubject(), "rdfs:comment", next.asLiteral().getString()); } } } } iwriter.commit(); iwriter.close(); } catch (IOException e) { log.error(e.getLocalizedMessage(), e); } } DBpediaIndex(); ArrayList<String> search(final String object); void close(); public String FIELD_NAME_SUBJECT; public String FIELD_NAME_PREDICATE; public String FIELD_NAME_OBJECT; }
@Test public void testIndex() { DBpediaIndex dboindex = new DBpediaIndex(); log.debug("Searching for: http: Assert.assertFalse(dboindex.search("currencies").contains("http: log.debug(dboindex.search("currencies").toString()); log.debug("Searching for: http: Assert.assertTrue(dboindex.search("vice-president").contains("http: log.debug(dboindex.search("vice-president").toString()); log.debug("Searching for: http: Assert.assertTrue(dboindex.search("currency").contains("http: log.debug(dboindex.search("currency").toString()); }