/** * Computes the CBDs of given depth for the given resources and puts them into a single model. * * @param resources the resource URIs * @param depth the max. depth of the CBDs * @return the CBDs in a single model */ default Model getConciseBoundedDescription(Set<String> resources, int depth) { return getConciseBoundedDescription(resources, depth, false); }
/** * Computes the CBD of given depth for the given resource. * * @param resource the resource URI * @param depth the max. depth of the CBD * @return the CBD */ default Model getConciseBoundedDescription(String resource, int depth) { return getConciseBoundedDescription(resource, depth, false); }
/** * Computes the CBDs (of given depth 1) for the given resources and puts them into a single model. * * @param resources the resource URIs * @return the CBDs in a single model */ default Model getConciseBoundedDescription(Set<String> resources) { return getConciseBoundedDescription(resources, 1); }
/** * Computes the CBD (of depth 1) for the given resource. * * @param resource the resource URI * @return the CBD */ default Model getConciseBoundedDescription(String resource) { return getConciseBoundedDescription(resource, 1); }
public Model load(CacheKey key) { return delegatee.getConciseBoundedDescription(key.resource, key.depth, key.withTypesForLeafs); } });
/** * Computes the CBD of given depth for the given resources and puts them into a single model. Optionally, additional * information about the types for the leaf nodes is retrieved. * * @param resources the resource URIs * @param depth the max. depth of the CBDs * @param withTypesForLeafs whether to get the types of the leaf nodes * * @return the CBDs in a single model */ default Model getConciseBoundedDescription(Set<String> resources, int depth, boolean withTypesForLeafs) { return resources.stream() .map(r -> getConciseBoundedDescription(r, depth, withTypesForLeafs)) .reduce(Model::union) .orElseThrow(() -> new RuntimeException("Failed to compute CBD for resources " + resources)); }
private OWLOntology extractSampleModule(String resource){ logger.info("Extracting sample module..."); long startTime = System.currentTimeMillis(); ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(ks.getQueryExecutionFactory()); Model model = cbdGen.getConciseBoundedDescription(resource, 3); OWLOntology data = convert(model); logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); return data; }
private OWLOntology extractSampleModule(Set<String> resources){ logger.info("Extracting sample module..."); long startTime = System.currentTimeMillis(); ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(ks.getQueryExecutionFactory()); Model model = ModelFactory.createDefaultModel(); for(String resource : resources){ model.add(cbdGen.getConciseBoundedDescription(resource, depth)); } logger.info("...done in " + (System.currentTimeMillis()-startTime) + "ms."); return convert(model); }
public static void main(String[] args) { SparqlEndpoint endpoint = SparqlEndpoint.getEndpointDBpedia(); Set<String> ignoredProperties = Sets.newHashSet( "http://dbpedia.org/ontology/abstract", "http://dbpedia.org/ontology/wikiPageID", "http://dbpedia.org/ontology/wikiPageRevisionID", "http://dbpedia.org/ontology/wikiPageID"); ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(endpoint); // cbdGen.setIgnoredProperties(ignoredProperties); // cbdGen.setAllowedPropertyNamespaces(Sets.newHashSet("http://dbpedia.org/ontology/")); // cbdGen.setAllowedClassNamespaces(Sets.newHashSet("http://dbpedia.org/ontology/")); // cbdGen.setAllowedObjectNamespaces(Sets.newHashSet("http://dbpedia.org/resource/")); cbdGen = new CachingConciseBoundedDescriptionGenerator(cbdGen); // cbdGen.setRestrictToNamespaces(Arrays.asList(new String[]{"http://dbpedia.org/ontology/", RDF.getURI(), RDFS.getURI()})); Model cbd = cbdGen.getConciseBoundedDescription(Sets.newHashSet("http://dbpedia.org/resource/Leipzig", "http://dbpedia.org/resource/Dresden"),2); System.out.println(cbd.size()); }
@Override public Model call() throws Exception { ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(ks.getQueryExecutionFactory()); return cbdGen.getConciseBoundedDescription(ind.toStringID(), 2); } }));
@Override public Model extractFragment(OWLClass cls, int maxFragmentDepth) { startTime = System.currentTimeMillis(); Model fragment = ModelFactory.createDefaultModel(); //get some random individuals Set<OWLIndividual> individuals = getRandomIndividuals(cls); //get for each individual the CBD Model cbd; for (OWLIndividual ind : individuals) { cbd = cbdGen.getConciseBoundedDescription(ind.toStringID(), maxFragmentDepth); fragment.add(cbd); } return fragment; }
private RDFResourceTree getTree(String uri) { return treeFactory.getQueryTree(uri, cbdGenerator.getConciseBoundedDescription(uri, maxDepth), maxDepth); }
public static void main(String[] args) throws Exception{ org.apache.log4j.Logger.getRootLogger().setLevel(Level.DEBUG); SparqlEndpoint endpoint = SparqlEndpoint.create("http://sake.informatik.uni-leipzig.de:8890/sparql", "http://dbpedia.org"); // endpoint = SparqlEndpoint.getEndpointDBpedia(); ConciseBoundedDescriptionGenerator cbdGen = new SymmetricConciseBoundedDescriptionGeneratorImpl(endpoint); Resource res = ResourceFactory.createResource("http://dbpedia.org/resource/Santa_Clara,_California"); Model cbd = cbdGen.getConciseBoundedDescription(res.getURI(), 2); System.out.println("#triples =\t" + cbd.size()); System.out.println("#triples_out =\t" + cbd.listStatements(res, null, (RDFNode) null).toSet().size()); cbd.listStatements(res, null, (RDFNode) null).toList().forEach(System.out::println); System.out.println("#triples_in =\t" + cbd.listStatements(null, null, res).toSet().size()); cbd.listStatements(null, null, res).toList().forEach(System.out::println); }
private Model getFragment(SparqlEndpointKS ks, Set<OWLIndividual> individuals){ ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl(ks.getQueryExecutionFactory()); Model model = ModelFactory.createDefaultModel(); for(OWLIndividual ind : individuals){ Model cbd = cbdGen.getConciseBoundedDescription(ind.toStringID(), 2); model.add(cbd); } return model; }
private RDFResourceTree getQueryTree(String resource){ Model cbd = cbdGen.getConciseBoundedDescription(resource, maxDepth); try(ByteArrayOutputStream baos = new ByteArrayOutputStream()){ cbd.write(baos, "N-TRIPLES", null); String modelAsString = new String(baos.toByteArray()); modelAsString = modelAsString.replace("NAN", "NaN"); Model newModel = ModelFactory.createDefaultModel(); newModel.read(new StringReader(modelAsString), null, "TURTLE"); cbd = newModel; } catch (IOException e) { e.printStackTrace(); } RDFResourceTree tree = queryTreeFactory.getQueryTree(resource, cbd); return tree; }
public static void main(String[] args) throws Exception { QueryTreeFactory factory = new QueryTreeFactoryBase(); factory.setMaxDepth(2); factory.addDropFilters( new PredicateDropStatementFilter(Sets.union(Sets.union(StopURIsDBpedia.get(), StopURIsRDFS.get()), StopURIsOWL.get())), new ObjectDropStatementFilter(StopURIsOWL.get()), new NamespaceDropStatementFilter( Sets.newHashSet( "http://dbpedia.org/property/", "http://purl.org/dc/terms/", "http://dbpedia.org/class/yago/", FOAF.getURI() ) ) ); ConciseBoundedDescriptionGenerator cbdGen = new ConciseBoundedDescriptionGeneratorImpl( SparqlEndpoint.getEndpointDBpedia()); String resourceURI = "http://dbpedia.org/resource/Athens"; Model cbd = cbdGen.getConciseBoundedDescription(resourceURI, 2); RDFResourceTree queryTree = factory.getQueryTree(resourceURI, cbd); System.out.println(queryTree.getStringRepresentation()); System.out.println(QueryTreeUtils.toSPARQLQuery(queryTree)); }
Model m1 = cbdGen.getConciseBoundedDescription(ex1, depth); Model m2 = cbdGen.getConciseBoundedDescription(ex2, depth);
public static void main(String[] args) throws Exception { QueryTreeFactory factory = new QueryTreeFactoryBaseInv(); factory.setMaxDepth(2); factory.addDropFilters( new PredicateDropStatementFilter(Sets.union(Sets.union(StopURIsDBpedia.get(), StopURIsRDFS.get()), StopURIsOWL.get())), new ObjectDropStatementFilter(StopURIsOWL.get()), new NamespaceDropStatementFilter( Sets.newHashSet( "http://dbpedia.org/property/", "http://purl.org/dc/terms/", "http://dbpedia.org/class/yago/", FOAF.getURI() ) ) ); ConciseBoundedDescriptionGenerator cbdGen = new SymmetricConciseBoundedDescriptionGeneratorImpl( SparqlEndpoint.getEndpointDBpedia()); String resourceURI = "http://dbpedia.org/resource/Athens"; Model cbd = cbdGen.getConciseBoundedDescription(resourceURI, 1); RDFResourceTree queryTree = factory.getQueryTree(resourceURI, cbd); System.out.println(queryTree.getStringRepresentation()); System.out.println(QueryTreeUtils.toSPARQLQuery(queryTree)); }
private RDFResourceTree getSimilarTree(RDFResourceTree tree, String property, int maxTreeDepth){ String query = "SELECT ?o WHERE {?s <" + property + "> ?o. FILTER(isURI(?o) && ?o != <" + tree.getData() + ">)} LIMIT 1"; QueryExecution qe = qef.createQueryExecution(query); ResultSet rs = qe.execSelect(); if(rs.hasNext()){ Resource object = rs.next().getResource("o"); Model cbd = cbdGen.getConciseBoundedDescription(object.getURI(), maxTreeDepth); RDFResourceTree similarTree = queryTreeFactory.getQueryTree(object, cbd, maxTreeDepth); similarTree.setData(object.asNode()); return similarTree; } return null; }
private RDFResourceTree getSimilarTree(RDFResourceTree tree, String property, int maxTreeDepth){ String query = "SELECT ?o WHERE {?s <" + property + "> ?o. FILTER(isURI(?o) && ?o != <" + tree.getData() + ">)} LIMIT 1"; QueryExecution qe = qef.createQueryExecution(query); ResultSet rs = qe.execSelect(); if(rs.hasNext()){ Resource object = rs.next().getResource("o"); Model cbd = cbdGen.getConciseBoundedDescription(object.getURI(), maxTreeDepth); RDFResourceTree similarTree = queryTreeFactory.getQueryTree(object, cbd, maxTreeDepth); similarTree.setData(object.asNode()); return similarTree; } return null; }