本文整理了Java中org.apache.jena.graph.Graph
类的一些代码示例,展示了Graph
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Graph
类的具体详情如下:
包路径:org.apache.jena.graph.Graph
类名称:Graph
[英]The interface to be satisfied by implementations maintaining collections of RDF triples. The core interface is small (add, delete, find, contains) and is augmented by additional classes to handle more complicated matters such as event management.
[中]
代码示例来源:origin: org.spdx/spdx-tools
public String getComment() {
if (this.model != null && this.resource != null) {
Node p = model.getProperty(SpdxRdfConstants.RDFS_NAMESPACE, SpdxRdfConstants.RDFS_PROP_COMMENT).asNode();
Triple m = Triple.createMatch(this.resource.asNode(), p, null);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
this.comment = tripleIter.next().getObject().toString(false);
}
}
return this.comment;
}
代码示例来源:origin: vivo-project/Vitro
private void stageAddition(Triple t) {
if(removalsGraph.contains(t)) {
removalsGraph.remove(t.getSubject(), t.getPredicate(), t.getObject());
} else {
additionsGraph.add(t);
}
}
代码示例来源:origin: ch.epfl.bluebrain.nexus.org.topbraid/shacl
public static boolean exists(Graph graph) {
if(graph instanceof OptimizedMultiUnion) {
return ((OptimizedMultiUnion)graph).getIncludesSHACL();
}
else {
return graph != null &&
SH.NS.equals(graph.getPrefixMapping().getNsPrefixURI(SH.PREFIX)) &&
graph.contains(SH.Shape.asNode(), RDF.type.asNode(), Node.ANY);
}
}
代码示例来源:origin: apache/jena
/**
* Remove the triple, ie, remove it from the adds, add it to the removals.
*/
@Override
public void performDelete(Triple t)
{
additions.delete(t) ;
if (base.contains(t))
deletions.add(t) ;
}
代码示例来源:origin: apache/jena
@SuppressWarnings("deprecation")
@Override
protected final long writeOutput(Writer writer) {
if (this.g.size() == 0)
return 0;
RDFDataMgr.write(writer, this.g, this.getRdfLanguage());
this.g.clear();
return this.g.size();
}
代码示例来源:origin: apache/jena
@Override
public boolean doCheck( Node n, EnhGraph g ) {
return n.equals( RDF.nil.asNode() ) ||
g.asGraph().contains( n, RDF.type.asNode(), RDF.List.asNode() );
}
}
代码示例来源:origin: apache/jena
/**
* Test case for a bug in retrieving a value like 3.00 from
* a probe like 3.0
*/
public void testDecimalFind() {
RDFDatatype dt = XSDDatatype.XSDdecimal;
Node ns = NodeFactory.createURI("x") ;
Node np = NodeFactory.createURI("p") ;
Node nx1 = NodeFactory.createLiteral("0.50", dt) ;
Node nx2 = NodeFactory.createLiteral("0.500", dt) ;
Graph graph = Factory.createDefaultGraph() ;
graph.add(new Triple(ns, np, nx1)) ;
assertTrue( graph.find(Node.ANY, Node.ANY, nx2).hasNext() );
}
代码示例来源:origin: org.spdx/spdx-tools
public List<SpdxPackage> findAllPackages() throws InvalidSPDXAnalysisException {
Node rdfTypePredicate = model.getProperty(SpdxRdfConstants.RDF_NAMESPACE,
SpdxRdfConstants.RDF_PROP_TYPE).asNode();
Node packageTypeObject = model.createResource(SPDX_NAMESPACE + CLASS_SPDX_PACKAGE).asNode();
Triple m = Triple.createMatch(null, rdfTypePredicate, packageTypeObject);
List<SpdxPackage> retval = Lists.newArrayList();
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
while (tripleIter.hasNext()) {
retval.add((SpdxPackage)SpdxElementFactory.createElementFromModel(this, tripleIter.next().getSubject()));
}
return retval;
}
代码示例来源:origin: apache/jena
@Test public void rdfjson_escapes()
{
Graph g = GraphFactory.createGraphMem();
Node s = NodeFactory.createBlankNode();
Node p = NodeFactory.createURI("http://predicate");
g.add(new Triple(s, p, NodeFactory.createLiteral("quote \" character")));
g.add(new Triple(s, p, NodeFactory.createLiteral("new \n\r lines")));
g.add(new Triple(s, p, NodeFactory.createLiteral("tab \t character")));
test(g);
}
代码示例来源:origin: apache/jena
static private void findContainers(Collection<Node> acc, Graph graph, Node typeNode)
{
ExtendedIterator<Triple> iter = graph.find(Node.ANY, RDF.type.asNode(), typeNode) ;
while(iter.hasNext())
{
Triple t = iter.next();
Node containerNode = t.getSubject() ;
acc.add(containerNode) ;
}
}
代码示例来源:origin: apache/jena
@Test public void sparql5()
{
Dataset dataset = create() ;
String graphName = "http://example/" ;
Triple triple = SSE.parseTriple("(<x> <y> 123)") ;
Graph g2 = dataset.asDatasetGraph().getGraph(NodeFactory.createURI(graphName)) ;
// Graphs only exists if they have a triple in them
g2.add(triple) ;
Query query = QueryFactory.create("ASK { GRAPH <"+graphName+"> {} }") ;
boolean b = QueryExecutionFactory.create(query, dataset).execAsk() ;
assertEquals(true, b) ;
}
代码示例来源:origin: org.spdx/spdx-tools
/**
* @param id
* @return true if the license ID is already in the model as an extracted license info
* @throws InvalidSPDXAnalysisException
*/
protected boolean extractedLicenseExists(String id) throws InvalidSPDXAnalysisException {
Node p = model.getProperty(SPDX_NAMESPACE, PROP_LICENSE_ID).asNode();
Node o = NodeFactory.createLiteral(id);
Triple m = Triple.createMatch(null, p, o);
ExtendedIterator<Triple> tripleIter = model.getGraph().find(m);
return tripleIter.hasNext();
}
代码示例来源:origin: apache/jena
@Test public void graph_02()
{
Node g = NodeFactory.createURI("g") ;
DatasetGraph dsg = emptyDataset() ;
assertNotNull(dsg) ;
Quad quad = SSE.parseQuad("(quad <g> <s> <p> <o>)") ;
dsg.add(quad) ;
Triple t = SSE.parseTriple("(<s> <p> <o>)") ;
dsg.getGraph(g).delete(t) ;
assertTrue(dsg.getDefaultGraph().isEmpty()) ;
assertTrue(dsg.getGraph(NodeFactory.createURI("g")).isEmpty()) ;
assertFalse(dsg.find(Node.ANY, Node.ANY, Node.ANY, Node.ANY).hasNext()) ;
}
代码示例来源:origin: apache/jena
@Override
public boolean doCheck( Node n, EnhGraph g ) {
return n.isBlank() &&
g.asGraph().contains( n, RDF.type.asNode(), OWL.DataRange.asNode() );
}
}
代码示例来源:origin: apache/jena
@Override
public Model add( Resource s, Property p, RDFNode o ) {
modelReifier.noteIfReified( s, p, o );
graph.add( Triple.create( s.asNode(), p.asNode(), o.asNode() ) );
return this;
}
代码示例来源:origin: org.aksw.jena-sparql-api/jena-sparql-api-mapper
@Override
public void writeValue(Object value, Node subject, Node predicate,
Graph outputGraph) {
if(value != null) {
// value must be a string
String iri = value.toString();
Node o = NodeFactory.createURI(iri);
Triple t = new Triple(subject, predicate, o);
outputGraph.add(t);
}
}
代码示例来源:origin: apache/jena
@Override
public void runBare()
{
Graph g = graphWith( graph );
Node literal = NodeCreateUtils.create( search );
//
assertEquals( "graph has wrong size", size, g.size() );
Set<Node> got = g.find( Node.ANY, Node.ANY, literal ).mapWith( t -> t.getObject() ).toSet();
assertEquals( nodeSet( results ), got );
}
};
代码示例来源:origin: apache/jena
@Override
public Model remove( Resource s, Property p, RDFNode o ) {
graph.delete( Triple.create( s.asNode(), p.asNode(), o.asNode() ) );
return this;
}
代码示例来源:origin: apache/jena
@Test public void quad_02()
{
DatasetGraph dsg = emptyDataset() ;
assertNotNull(dsg) ;
Quad quad = SSE.parseQuad("(quad <g> <s> <p> <o>)") ;
dsg.add(quad) ;
dsg.containsGraph(NodeFactory.createURI("g")) ;
dsg.delete(quad) ;
assertTrue(dsg.isEmpty()) ;
assertTrue(dsg.getDefaultGraph().isEmpty()) ;
assertTrue(dsg.getGraph(NodeFactory.createURI("g")).isEmpty()) ;
}
代码示例来源:origin: apache/jena
@Before
public void setUp() throws Exception {
baseGraph = createGraph();
baseGraph.remove(Node.ANY, Node.ANY, Node.ANY);
securedGraph = org.apache.jena.permissions.Factory
.getInstance(securityEvaluator,
"http://example.com/securedGraph", baseGraph);
s = NodeFactory.createURI("http://example.com/securedGraph/s");
p = NodeFactory.createURI("http://example.com/securedGraph/p");
o = NodeFactory.createURI("http://example.com/securedGraph/o");
t = new Triple(s, p, o);
baseGraph.add(t);
}
内容来源于网络,如有侵权,请联系作者删除!