org.openrdf.model.impl.GraphImpl Java Examples
The following examples show how to use
org.openrdf.model.impl.GraphImpl.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryEvaluation.java From CostFed with GNU Affero General Public License v3.0 | 7 votes |
protected Graph parseConfig(File file) throws SailConfigException, IOException { RDFFormat format = Rio.getParserFormatForFileName(file.getAbsolutePath()); if (format==null) throw new SailConfigException("Unsupported file format: " + file.getAbsolutePath()); RDFParser parser = Rio.createParser(format); Graph model = new GraphImpl(); parser.setRDFHandler(new StatementCollector(model)); InputStream stream = new FileInputStream(file); try { parser.parse(stream, file.getAbsolutePath()); } catch (Exception e) { throw new SailConfigException("Error parsing file!"); } stream.close(); return model; }
Example #2
Source File: EntityTypeSerializer.java From attic-polygene-java with Apache License 2.0 | 6 votes |
public Iterable<Statement> serialize( final EntityDescriptor entityDescriptor ) { Graph graph = new GraphImpl(); ValueFactory values = graph.getValueFactory(); URI entityTypeUri = values.createURI( Classes.toURI( entityDescriptor.types().findFirst().orElse( null ) ) ); graph.add( entityTypeUri, Rdfs.TYPE, Rdfs.CLASS ); graph.add( entityTypeUri, Rdfs.TYPE, OWL.CLASS ); graph.add( entityTypeUri, PolygeneEntityType.TYPE, values.createLiteral( entityDescriptor.types().findFirst().get().toString() ) ); graph.add( entityTypeUri, PolygeneEntityType.QUERYABLE, values.createLiteral( entityDescriptor.queryable() ) ); serializeMixinTypes( entityDescriptor, graph, entityTypeUri ); serializePropertyTypes( entityDescriptor, graph, entityTypeUri ); serializeAssociationTypes( entityDescriptor, graph, entityTypeUri ); serializeManyAssociationTypes( entityDescriptor, graph, entityTypeUri ); return graph; }
Example #3
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void flushUpdates() throws SailException { super.flushUpdates(); if (this.statementsRemoved) { this.logger.debug("statements removed, starting inferencing from scratch"); clearInferred(); addAxiomStatements(); this.newStatements = new GraphImpl(); Iterations.addAll(getWrappedConnection().getStatements(null, null, null, true), this.newStatements); this.statementsRemoved = false; } doInferencing(); }
Example #4
Source File: JenaSesameUtils.java From anno4j with Apache License 2.0 | 5 votes |
/** * Convert the Jena Model to a Sesame Graph * @param theModel the model to convert * @return the set of statements in the Jena model saved in a sesame Graph */ public static Graph asSesameGraph(Model theModel) { Graph aGraph = new GraphImpl(); StmtIterator sIter = theModel.listStatements(); while (sIter.hasNext()) { aGraph.add(asSesameStatement(sIter.nextStatement())); } sIter.close(); return aGraph; }
Example #5
Source File: EntityStateSerializer.java From attic-polygene-java with Apache License 2.0 | 5 votes |
public Iterable<Statement> serialize( final EntityState entityState, final boolean includeNonQueryable ) { Graph graph = new GraphImpl(); serialize( entityState, includeNonQueryable, graph ); return graph; }
Example #6
Source File: ApplicationSerializer.java From attic-polygene-java with Apache License 2.0 | 5 votes |
public Graph serialize( Application app ) { Graph graph = new GraphImpl(); SerializerContext context = new SerializerContext( graph ); ApplicationVisitor applicationVisitor = new ApplicationVisitor( context ); app.descriptor().accept( applicationVisitor ); return graph; }
Example #7
Source File: RdfIndexerService.java From attic-polygene-java with Apache License 2.0 | 5 votes |
private void indexEntityState( final EntityState entityState, final RepositoryConnection connection ) throws RepositoryException { if( entityState.entityDescriptor().queryable() ) { EntityReference reference = entityState.entityReference(); final URI entityURI = stateSerializer.createEntityURI( getValueFactory(), reference); Graph graph = new GraphImpl(); stateSerializer.serialize( entityState, false, graph ); connection.add( graph, entityURI ); } }
Example #8
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
public void statementAdded(Statement st) { if (this.statementsRemoved) { // No need to record, starting from scratch anyway return; } if (this.newStatements == null) { this.newStatements = new GraphImpl(); } this.newStatements.add(st); }
Example #9
Source File: ForwardChainingRDFSInferencerConnection.java From semweb4j with BSD 2-Clause "Simplified" License | 5 votes |
protected void prepareIteration() { for (int i = 0; i < RDFSPlusInversesRules.RULECOUNT; i++) { this.checkRule[i] = this.checkRuleNextIter[i]; // reset for next iteration: this.checkRuleNextIter[i] = false; } this.newThisIteration = this.newStatements; this.newStatements = new GraphImpl(); }
Example #10
Source File: DemoSesameServer.java From database with GNU General Public License v2.0 | 4 votes |
public static void _main(String[] args) throws Exception { String sesameURL, repoID; if (args != null && args.length == 2) { sesameURL = args[0]; repoID = args[1]; } else { sesameURL = DemoSesameServer.sesameURL; repoID = DemoSesameServer.repoID; } Repository repo = new HTTPRepository(sesameURL, repoID); repo.initialize(); RepositoryConnection cxn = repo.getConnection(); cxn.setAutoCommit(false); try { // load some statements built up programmatically URI mike = new URIImpl(BD.NAMESPACE + "Mike"); URI bryan = new URIImpl(BD.NAMESPACE + "Bryan"); URI loves = new URIImpl(BD.NAMESPACE + "loves"); URI rdf = new URIImpl(BD.NAMESPACE + "RDF"); Graph graph = new GraphImpl(); graph.add(mike, loves, rdf); graph.add(bryan, loves, rdf); cxn.add(graph); cxn.commit(); } finally { cxn.close(); } { // show the entire contents of the repository SparqlBuilder sparql = new SparqlBuilder(); sparql.addTriplePattern("?s", "?p", "?o"); GraphQuery query = cxn.prepareGraphQuery( QueryLanguage.SPARQL, sparql.toString()); GraphQueryResult result = query.evaluate(); while (result.hasNext()) { Statement stmt = result.next(); System.err.println(stmt); } } }
Example #11
Source File: Test_REST_DESCRIBE.java From database with GNU General Public License v2.0 | 4 votes |
protected void doStressDescribeTest(final String method, final RDFFormat format, final int tasks, final int threads, final int statements) throws Exception { final URI person = new URIImpl(BD.NAMESPACE + "Person"); final URI likes = new URIImpl(BD.NAMESPACE + "likes"); final URI rdf = new URIImpl(BD.NAMESPACE + "RDF"); final URI rdfs = new URIImpl(BD.NAMESPACE + "RDFS"); { // create a large number of mikes and bryans final Graph g = new GraphImpl(); for (int n = 0; n < statements; n++) { final URI miken = new URIImpl(BD.NAMESPACE + "Mike#" + n); final URI bryann = new URIImpl(BD.NAMESPACE + "Bryan#" + n); final Literal nameMiken = new LiteralImpl("Mike#" + n); final Literal nameBryann = new LiteralImpl("Bryan#" + n); g.add(miken, RDF.TYPE, person); g.add(miken, likes, rdf); g.add(miken, RDFS.LABEL, nameMiken); g.add(bryann, RDF.TYPE, person); g.add(bryann, likes, rdfs); g.add(bryann, RDFS.LABEL, nameBryann); } m_repo.add(new AddOp(g)); } // Run the DESCRIBE query and verify the results (non-empty). { final String queryStr = "prefix bd: <" + BD.NAMESPACE + "> " + // "prefix rdf: <" + RDF.NAMESPACE + "> " + // "prefix rdfs: <" + RDFS.NAMESPACE + "> " + // "DESCRIBE ?x " + // "WHERE { " + // " ?x rdf:type bd:Person . " + // " ?x bd:likes bd:RDF " + // "}"; final AtomicInteger errorCount = new AtomicInteger(); final Callable<Void> task = new Callable<Void>() { @Override public Void call() throws Exception { try { final Graph actual = asGraph(m_repo .prepareGraphQuery(queryStr)); assertTrue(!actual.isEmpty()); return null; } catch (Exception e) { log.warn("Call failure", e); errorCount.incrementAndGet(); throw e; } } }; final int threadCount = Thread.activeCount(); final ExecutorService exec = Executors.newFixedThreadPool(threads); for (int r = 0; r < tasks; r++) { exec.submit(task); } exec.shutdown(); exec.awaitTermination(2000, TimeUnit.SECONDS); // force shutdown exec.shutdownNow(); int loops = 20; while (Thread.activeCount() > threadCount && --loops > 0) { Thread.sleep(500); if (log.isTraceEnabled()) log.trace("Extra threads: " + (Thread.activeCount() - threadCount)); } if (log.isInfoEnabled()) log.info("Return with extra threads: " + (Thread.activeCount() - threadCount)); assertTrue(errorCount.get() == 0); } }
Example #12
Source File: DescribeCacheUpdater.java From database with GNU General Public License v2.0 | 4 votes |
/** * Associate the statement with the resource. It is part of the * description of that resource. * * @param describedResource * A resource that is being described. * @param stmt * A statement having that resource as either the subject or * object. */ private void record(final BigdataValue describedResource, final BigdataStatement stmt) { Graph g = graphs.get(describedResource); if(g == null) { graphs.put(describedResource, g = new GraphImpl()); } g.add(stmt); if (log.isDebugEnabled()) log.debug("DESCRIBE: describedResource=" + describedResource + ", statement=" + stmt); }
Example #13
Source File: NanoSparqlClient.java From database with GNU General Public License v2.0 | 3 votes |
/** * Builds a graph from an RDF result set (statements, not binding sets). * * @param conn * The connection from which to read the results. * * @return The graph * * @throws Exception * If anything goes wrong. */ protected Graph buildGraph(final HttpURLConnection conn) throws Exception { final Graph g = new GraphImpl(); try { final String baseURI = ""; final RDFParser rdfParser = RDFParserRegistry.getInstance() .get(RDFFormat.RDFXML) .getParser(); rdfParser.setVerifyData(true); rdfParser.setStopAtFirstError(true); rdfParser.setDatatypeHandling(RDFParser.DatatypeHandling.IGNORE); rdfParser.setRDFHandler(new StatementCollector(g)); rdfParser.parse(conn.getInputStream(), baseURI); return g; } finally { // // terminate the http connection. // conn.disconnect(); } }