public static Graph getGraph() { Graph g = Factory.createGraphMem(); g.add(new Triple(NodeFactory.createURI("http://example.com/subject"), NodeFactory.createURI("http://example.com/predicate"), NodeFactory.createURI("http://example.com/object"))); g.add(new Triple(NodeFactory.createBlankNode(BlankNodeId.create("a")), NodeFactory.createURI("http://example.com/p1"), NodeFactory .createBlankNode(BlankNodeId.create("b")))); g.add(new Triple(NodeFactory.createBlankNode(BlankNodeId.create("b")), NodeFactory.createURI("http://example.com/p2"), NodeFactory .createLiteral("foo"))); g.add(new Triple(NodeFactory.createURI("http://example.com/ns/e"), NodeFactory.createURI("http://example.com/ns/p5"), NodeFactory .createLiteral("verify base works"))); return g; }
public void testVariables() { assertFalse( "variable nodes aren't blank", NodeFactory.createVariable( N ).isBlank() ); assertFalse( "variable nodes aren't literal", NodeFactory.createVariable( N ).isLiteral() ); assertFalse( "variable nodes aren't URIs", NodeFactory.createVariable( N ).isURI() ); assertTrue( "variable nodes are variable", NodeFactory.createVariable( N ).isVariable() ); assertEquals( "variable nodes keep their name", N, NodeFactory.createVariable( N ).getName() ); assertEquals( "variable nodes keep their name", N + "x", NodeFactory.createVariable( N + "x" ).getName() ); }
public static NodeValue strDatatype(NodeValue v1, NodeValue v2) { if ( !v1.isString() ) throw new ExprEvalException("Not a string (arg 1): " + v1) ; if ( !v2.isIRI() ) throw new ExprEvalException("Not an IRI (arg 2): " + v2) ; String lex = v1.asString() ; Node dt = v2.asNode() ; // Check? Node n = NodeFactory.createLiteral(lex, NodeFactory.getType(dt.getURI())) ; return NodeValue.makeNode(n) ; }
private Triple getTriple2() { Node n1 = NodeFactory.createURI("nb1") ; Node n2 = NodeFactory.createURI("nb2") ; Node l3 = NodeFactory.createLiteral("lb3") ; return new Triple(n1, n2, l3) ; }
@Before public void setup() { triples = new Triple[] { new Triple(NodeFactory.createVariable("foo"), RDF.type.asNode(), NodeFactory.createURI("http://example.com/class")), new Triple(NodeFactory.createVariable("foo"), NodeFactory.createBlankNode(), NodeFactory.createVariable("bar")), new Triple(NodeFactory.createVariable("bar"), NodeFactory.createBlankNode(), NodeFactory.createVariable("baz")), }; }
public void testURIs() { assertFalse( "URI nodes aren't blank", NodeFactory.createURI( U ).isBlank() ); assertFalse( "URI nodes aren't literal", NodeFactory.createURI( U ).isLiteral() ); assertFalse( "URI nodes aren't variables", NodeFactory.createURI( U ).isVariable() ); assertTrue( "URI nodes are URIs", NodeFactory.createURI( U ).isURI() ); assertEquals( "URI nodes preserve URI", NodeFactory.createURI( U ).getURI(), U ); }
/** test that the label of a Node can be retrieved from that Node in a way appropriate to that Node. */ public void testLabels() { BlankNodeId id = BlankNodeId.create(); assertEquals( "get URI value", U, NodeFactory.createURI( U ).getURI() ); assertEquals( "get blank value", id, NodeFactory.createBlankNode( id ).getBlankNodeId() ); assertEquals( "get literal value", L, NodeFactory.createLiteral( L ).getLiteral() ); assertEquals( "get variable name", N, NodeFactory.createVariable( N ).getName() ); }
@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) ; }
@Override public SecuredModel add(final Resource s, final Property p, final String lex, final RDFDatatype datatype) throws UpdateDeniedException, AddDeniedException, AuthenticationRequiredException { checkUpdate(); checkCreate(new Triple(s.asNode(), p.asNode(), NodeFactory.createLiteral(lex, datatype))); holder.getBaseItem().add(s, p, lex, datatype); return holder.getSecuredItem(); }
/** * 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() ); }
@Test public void binaryThrift() { Triple t = Triple.create(n(":s"), n(":p"), NodeFactory.createBlankNode("ABCD")); Node obj = t.getObject(); Graph graph = Factory.createDefaultGraph(); graph.add(t); ByteArrayOutputStream bout = new ByteArrayOutputStream(); RDFDataMgr.write(bout, graph, Lang.RDFTHRIFT); ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); Graph graph1 = Factory.createDefaultGraph(); RDFDataMgr.read(graph1, bin, Lang.RDFTHRIFT); Node obj1 = graph1.find().next().getObject(); assertEquals(obj, obj1); assertTrue(obj1.isBlank()); assertEquals(obj.getBlankNodeLabel(), obj1.getBlankNodeLabel()); }
@Override protected NodeWritable[] getNodes(TripleWritable tuple) { Node object = tuple.get().getObject(); if (!object.isLiteral()) return EMPTY; String dtUri = object.getLiteralDatatypeURI(); if (dtUri == null) return EMPTY; return new NodeWritable[] { new NodeWritable(NodeFactory.createURI(dtUri)) }; } }
/** * @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(); }
public void testEquals() { assertDiffer( "different variables", NodeFactory.createVariable( "xx" ), NodeFactory.createVariable( "yy" ) ); assertEquals( "same vars", NodeFactory.createVariable( "aa" ), NodeFactory.createVariable( "aa" ) ); assertEquals( "same URI", NodeFactory.createURI( U ), NodeFactory.createURI( U ) ); assertEquals( "same anon", NodeFactory.createBlankNode( A ), NodeFactory.createBlankNode( A ) ); assertEquals( "same literal", NodeFactory.createLiteral( L ), NodeFactory.createLiteral( L ) ); assertFalse( "distinct URIs", NodeFactory.createURI( U ) == NodeFactory.createURI( U ) ); assertFalse( "distinct hyphens", NodeFactory.createBlankNode( A ) == NodeFactory.createBlankNode( A ) ); assertFalse( "distinct literals", NodeFactory.createLiteral( L ) == NodeFactory.createLiteral( L ) ); assertFalse( "distinct vars", NodeFactory.createVariable( "aa" ) == NodeFactory.createVariable( "aa" ) ); }
@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()) ; }
@Override public void loadPrefixMapping(String graphName, PrefixMapping pmap) { Node g = NodeFactory.createURI(graphName) ; Iterator<Tuple<Node>> iter = nodeTupleTable.find(g, null, null) ; iter.forEachRemaining(tuple->{ Node prefix = tuple.get(1) ; Node uri = tuple.get(2) ; pmap.setNsPrefix(prefix.getLiteralLexicalForm(), uri.getURI()) ; }) ; }
@Override public SecuredStatement createStatement(final Resource s, final Property p, final String o) throws UpdateDeniedException, AddDeniedException, AuthenticationRequiredException { checkUpdate(); checkCreate(new Triple(s.asNode(), p.asNode(), NodeFactory.createURI(o))); return SecuredStatementImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem().createStatement(s, p, o)); }
@Test public void quad_01() { DatasetGraph dsg = emptyDataset() ; assertNotNull(dsg) ; Quad quad = SSE.parseQuad("(quad <g> <s> <p> <o>)") ; dsg.add(quad) ; assertTrue(dsg.contains(quad)) ; Iterator<Quad> iter = dsg.find(quad) ; assertTrue(iter.hasNext()) ; Quad quad2 = iter.next(); assertFalse(iter.hasNext()) ; assertEquals(quad, quad2) ; // and the graph view. assertTrue(dsg.getDefaultGraph().isEmpty()) ; assertFalse(dsg.getGraph(NodeFactory.createURI("g")).isEmpty()) ; }
@Override public SecuredSeq createSeq(final String uri) throws UpdateDeniedException, AddDeniedException, AuthenticationRequiredException { checkUpdate(); checkCreate(new Triple(NodeFactory.createURI(uri), RDF.type.asNode(), RDF.Alt.asNode())); return SecuredSeqImpl.getInstance(holder.getSecuredItem(), holder.getBaseItem().createSeq(uri)); }