/** * Convert a URI string to an RDF node * * @param r the uri string * @return RDF node representation of the given string */ public Node asLiteralStringNode(final String r) { return ResourceFactory.createPlainLiteral(r).asNode(); }
private void updatePeoplePageDisplayModel(OntModel displayModel, Model addStatements, Model removeStatements) { Resource peoplePage = displayModel.getResource(DisplayVocabulary.DISPLAY_NS + "People"); if(peoplePage != null) { removeStatements.add(peoplePage, DisplayVocabulary.REQUIRES_BODY_TEMPLATE, ResourceFactory.createPlainLiteral("menupage--classgroup-people.ftl")); } log.debug("Will remove body template from people page so added that to remove statements "); }
@Test public void test_set_values_items_parenthesis() { // Tests two values for same variable. String str = "SELECT * WHERE { VALUES (?o) {?objs} ?s ?p ?o }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); List<RDFNode> objs = new ArrayList<>(); objs.add(ResourceFactory.createPlainLiteral("obj_A")); objs.add(ResourceFactory.createPlainLiteral("obj_B")); pss.setValues("objs", objs); String exp = "SELECT * WHERE { VALUES (?o) {(\"obj_A\") (\"obj_B\")} ?s ?p ?o }"; String res = pss.toString(); //System.out.println("Exp: " + exp); //System.out.println("Res: " + res); Assert.assertEquals(exp, res); }
@Test(expected = ARQException.class) public void test_set_values_multiple_variables_too_many() { // Test of three values for two variables. String str = "SELECT * WHERE { VALUES (?p ?o) {?vars} ?s ?p ?o }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); List<RDFNode> vars = new ArrayList<>(); vars.add(ResourceFactory.createProperty("http://example.org/prop_A")); vars.add(ResourceFactory.createPlainLiteral("obj_A")); vars.add(ResourceFactory.createPlainLiteral("obj_A")); pss.setValues("vars", vars); pss.toString(); Assert.fail("Attempt to insert incorrect number of values."); }
/** * <p>Remove the statement that the given string provides version information about * this resource. If this statement * is not true of the current model, nothing happens.</p> * @param info A version information string to be removed */ @Override public void removeVersionInfo( String info ) { checkProfile( getProfile().VERSION_INFO(), "VERSION_INFO" ); Literal infoAsLiteral = ResourceFactory.createPlainLiteral( info ); getModel().remove( this, getProfile().VERSION_INFO(), infoAsLiteral ); }
/** * <p>Remove the statement that the given string provides version information about * this resource. If this statement * is not true of the current model, nothing happens.</p> * @param info A version information string to be removed */ @Override public void removeVersionInfo( String info ) { checkProfile( getProfile().VERSION_INFO(), "VERSION_INFO" ); Literal infoAsLiteral = ResourceFactory.createPlainLiteral( info ); getModel().remove( this, getProfile().VERSION_INFO(), infoAsLiteral ); }
@Test public void test_set_values_multiple_variables() { // Tests two values for same variable. String str = "SELECT * WHERE { VALUES (?p ?o) {?vars} ?s ?p ?o }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); List<RDFNode> vars = new ArrayList<>(); vars.add(ResourceFactory.createProperty("http://example.org/prop_A")); vars.add(ResourceFactory.createPlainLiteral("obj_A")); pss.setValues("vars", vars); String exp = "SELECT * WHERE { VALUES (?p ?o) {(<http://example.org/prop_A> \"obj_A\")} ?s ?p ?o }"; String res = pss.toString(); //System.out.println("Exp: " + exp); //System.out.println("Res: " + res); Assert.assertEquals(exp, res); }
@Override public SecuredResIterator listSubjectsWithProperty(final Property p, final String o) throws ReadDeniedException, AuthenticationRequiredException { checkRead(); ExtendedIterator<Resource> rIter = holder.getBaseItem().listSubjectsWithProperty(p, o); if (!canRead(Triple.ANY)) { rIter = rIter.filterKeep(new ResourceFilter(p, ResourceFactory.createPlainLiteral(o))); } return new SecuredResIterator(holder.getSecuredItem(), rIter); }
@Test public void literalObject_justSubjectResult() { setPredicateRestrictions(); exerciseUriFinder(BOB, SEES, createPlainLiteral("Bogus")); assertExpectedUris(BETTY_URI); }
public void testCreateLiteral() { final Literal l = ResourceFactory.createPlainLiteral("lex"); Assert.assertTrue(l.getLexicalForm().equals("lex")); Assert.assertTrue(l.getLanguage().equals("")); Assert.assertNull(l.getDatatype()); Assert.assertNull(l.getDatatypeURI()); }
public void testCreateLiteral() { final Literal l = ResourceFactory.createPlainLiteral("lex"); Assert.assertTrue(l.getLexicalForm().equals("lex")); Assert.assertTrue(l.getLanguage().equals("")); Assert.assertNull(l.getDatatype()); Assert.assertNull(l.getDatatypeURI()); }
@Test public void test_set_values_item_missing_valueName() { // valueName missing ('props' instead of 'objs') so query is unchanged. String str = "SELECT * WHERE { VALUES ?o {?objs} ?s ?p ?o }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setValues("props", ResourceFactory.createPlainLiteral("test")); String exp = "SELECT * WHERE { VALUES ?o {?objs} ?s ?p ?o }"; String res = pss.toString(); //System.out.println("Exp: " + exp); //System.out.println("Res: " + res); Assert.assertEquals(exp, res); }
@Test public void test_set_values_item() { // Tests a single value being added - always adding parenthesis. String str = "SELECT * WHERE { VALUES ?o {?objs} ?s ?p ?o }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setValues("objs", ResourceFactory.createPlainLiteral("test")); String exp = "SELECT * WHERE { VALUES ?o {(\"test\")} ?s ?p ?o }"; String res = pss.toString(); //System.out.println("Exp: " + exp); //System.out.println("Res: " + res); Assert.assertEquals(exp, res); }
@Test public void test_set_values_item2() { // Tests a single value being added using '$' variable syntax - always adding parenthesis. String str = "SELECT * WHERE { VALUES $o {$objs} $s $p $o }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setValues("objs", ResourceFactory.createPlainLiteral("test")); String exp = "SELECT * WHERE { VALUES $o {(\"test\")} $s $p $o }"; String res = pss.toString(); //System.out.println("Exp: " + exp); //System.out.println("Res: " + res); Assert.assertEquals(exp, res); }
@Test public void test_set_values_item_missing_braces() { // Braces missing so query is unchanged. String str = "SELECT * WHERE { VALUES ?o ?objs ?s ?p ?o }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setValues("objs", ResourceFactory.createPlainLiteral("test")); String exp = "SELECT * WHERE { VALUES ?o ?objs ?s ?p ?o }"; String res = pss.toString(); //System.out.println("Exp: " + exp); //System.out.println("Res: " + res); Assert.assertEquals(exp, res); }
@Test public void test_set_values_item_missing_values() { // VALUES keyword missing so query is unchanged. String str = "SELECT * WHERE { ?o {?objs} ?s ?p ?o }"; ParameterizedSparqlString pss = new ParameterizedSparqlString(str); pss.setValues("objs", ResourceFactory.createPlainLiteral("test")); String exp = "SELECT * WHERE { ?o {?objs} ?s ?p ?o }"; String res = pss.toString(); //System.out.println("Exp: " + exp); //System.out.println("Res: " + res); Assert.assertEquals(exp, res); }
private static RDFNode stringliteral2node(final String literal) { final RdfLiteralJcrValueBuilder rdfLiteralJcrValueBuilder = new RdfLiteralJcrValueBuilder(literal); if (rdfLiteralJcrValueBuilder.hasLang()) { return createLangLiteral(rdfLiteralJcrValueBuilder.value(), rdfLiteralJcrValueBuilder.lang()); } else if (rdfLiteralJcrValueBuilder.isResource()) { return createResource(rdfLiteralJcrValueBuilder.value()); } else if (rdfLiteralJcrValueBuilder.hasDatatypeUri()) { return createTypedLiteral(rdfLiteralJcrValueBuilder.value(), rdfLiteralJcrValueBuilder.datatype()); } else { return createPlainLiteral(rdfLiteralJcrValueBuilder.value()); } }
/** * Check ability to report literals as well as resources as culprits */ public void testLiteralsInErrorReports() { RDFNode culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 42). (?X rb:violation error('test', 'arg')) <- (?S eg:p ?X)."); assertEquals( culprit, ResourceFactory.createTypedLiteral( new Integer(42) )); culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 'foo'). (?X rb:violation error('test', 'arg')) <- (?S eg:p ?X)."); assertEquals( culprit, ResourceFactory.createPlainLiteral("foo")); BuiltinRegistry.theRegistry.register( new SomeTriple() ); culprit = doTestLiteralsInErrorReports("-> (eg:a eg:p 42). (?X rb:violation error('test', 'arg')) <- (?S eg:p ?Y), someTriple(?X)."); assertTrue( culprit.isLiteral() ); Object val = ((Literal)culprit).getValue(); assertTrue( val instanceof Triple); }
@Test public void test_param_string_constructor_6() { // Test constructor with predefined parameters QuerySolutionMap map = new QuerySolutionMap(); Resource r = ResourceFactory.createResource("http://example.org"); map.add("s", r); Literal l = ResourceFactory.createPlainLiteral("example"); map.add("o", l); ParameterizedSparqlString query = new ParameterizedSparqlString("", map); Assert.assertEquals(r.asNode(), query.getParam("s")); Assert.assertEquals(l.asNode(), query.getParam("o")); }
@Test public void test_param_string_constructor_7() { // Test constructor with predefined parameters - variant of constructor // that does not require command text QuerySolutionMap map = new QuerySolutionMap(); Resource r = ResourceFactory.createResource("http://example.org"); map.add("s", r); Literal l = ResourceFactory.createPlainLiteral("example"); map.add("o", l); ParameterizedSparqlString query = new ParameterizedSparqlString(map); Assert.assertEquals(r.asNode(), query.getParam("s")); Assert.assertEquals(l.asNode(), query.getParam("o")); }