use of org.apache.jena.rdf.model.RDFNode in project loinc2hpo by monarch-initiative.
the class SparqlQuery method addFoundClasses.
public static int addFoundClasses(List<HPO_Class_Found> HPO_classes_found, Iterator<QuerySolution> results, LoincCodeClass loincClass) {
int count = 0;
while (results.hasNext()) {
count++;
QuerySolution next = results.next();
RDFNode pNode = next.get("phenotype");
RDFNode lNode = next.get("label");
RDFNode dNode = next.get("definition");
if (pNode.isResource() && lNode.isLiteral() && dNode != null && dNode.isLiteral()) {
HPO_classes_found.add(new HPO_Class_Found(pNode.toString(), lNode.toString(), dNode.toString(), loincClass));
} else if (pNode.isResource() && lNode.isLiteral() && dNode == null) {
HPO_classes_found.add(new HPO_Class_Found(pNode.toString(), lNode.toString(), null, loincClass));
} else {
// do nothing; not going to happen
}
}
return count;
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class AbstractTestRDFConnection method query_build_02.
@Test
public void query_build_02() {
try (RDFConnection conn = connection()) {
Txn.executeRead(conn, () -> {
QuerySolutionMap qsm = new QuerySolutionMap();
qsm.add("X", ResourceFactory.createTypedLiteral("123", XSDDatatype.XSDinteger));
QueryExecution qExec = conn.newQuery().query("SELECT ?X { }").substitution(qsm).build();
String s = qExec.getQueryString();
assertTrue(s.contains("123"));
ResultSet rs = qExec.execSelect();
RDFNode x = rs.next().get("X");
assertNotNull(x);
});
}
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class ShexTests method makeShexValidationTest.
/**
* Create a Shex test - or return null for "unrecognized"
*/
public static Runnable makeShexValidationTest(ManifestEntry entry) {
if (!runTestExclusionsInclusions(entry))
return null;
Resource testType = entry.getTestType();
if (testType == null) {
// RepresentationTest
System.out.println("No test type: " + entry.getName());
return null;
}
if (testType.equals(ShexT.cRepresentationTest)) {
return () -> {
};
}
Resource action = entry.getAction();
if (action == null) {
System.out.println("Action expected: " + entry.getName());
return null;
}
if (action.hasProperty(ShexT.semActs)) {
}
if (action.hasProperty(ShexT.shapeExterns)) {
}
if (testType == null) {
}
if (!testType.equals(ShexT.cValidationTest) && !testType.equals(ShexT.cValidationFailure)) {
System.err.println("Skip unknown test type for: " + entry.getName());
return () -> {
};
}
// map or (shape+focus)
if (!action.hasProperty(ShexT.schema)) {
System.err.println("Bad: no schema : " + entry.getName());
return null;
}
if (action.hasProperty(ShexT.map)) {
if (action.hasProperty(ShexT.shape) || action.hasProperty(ShexT.focus)) {
System.err.println("Bad: map + (shape or focus) : " + entry.getName());
}
if (!action.hasProperty(ShexT.data) || !action.hasProperty(ShexT.schema)) {
System.err.println("Bad: map + no (data+schema) : " + entry.getName());
}
} else {
// Not map
if (!action.hasProperty(ShexT.schema) || !action.hasProperty(ShexT.data) || !action.hasProperty(ShexT.focus))
System.err.println("Bad: no map, no (scheme/data/focus) : " + entry.getName());
}
if (testType.equals(ShexT.cValidationTest) || testType.equals(ShexT.cValidationFailure)) {
boolean faiureTest = testType.equals(ShexT.cValidationFailure);
if (action.hasProperty(ShexT.shape)) {
// Expected: ShexT.schema, ShexT.shape, ShexT.data, ShexT.focus
try {
Resource schema = action.getProperty(ShexT.schema).getResource();
Resource shape = action.getProperty(ShexT.shape).getResource();
Resource data = action.getProperty(ShexT.data).getResource();
// URI or literal.
RDFNode focus = action.getProperty(ShexT.focus).getObject();
return ShexValidationTest.testShexValidationShapeFocus(entry);
} catch (Exception ex) {
System.err.println(ex.getClass().getName());
System.err.println(ex.getMessage());
System.err.println(entry.getEntry().getLocalName());
return null;
}
}
// Roll into the above?
if (action.hasProperty(ShexT.focus)) {
// Expected: ShexT.schema (with start), ShexT.data, ShexT.focus
try {
Resource schema = action.getProperty(ShexT.schema).getResource();
// No shape.
Resource data = action.getProperty(ShexT.data).getResource();
// URI or literal.
RDFNode focus = action.getProperty(ShexT.focus).getObject();
return ShexValidationTest.testShexValidationStartFocus(entry);
} catch (Exception ex) {
}
}
if (action.hasProperty(ShexT.map)) {
// Expected: ShexT.schema (with start), ShexT.map, ShexT.data
try {
Resource schema = action.getProperty(ShexT.schema).getResource();
Resource map = action.getProperty(ShexT.map).getResource();
Resource data = action.getProperty(ShexT.data).getResource();
return ShexValidationTest.testShexValidationMap(entry);
} catch (Exception ex) {
System.err.println(ex.getClass().getName());
System.err.println(ex.getMessage());
System.err.println(entry.getEntry().getLocalName());
return null;
}
}
// Unknown.
System.err.println("Unknown: " + entry.getName());
return null;
} else {
Log.warn("ShexTests", "Skip unknown test type for: " + entry.getName());
return null;
}
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class SecuredSeqImpl method remove.
/**
* @sec.graph Update
* @sec.triple Delete SecTriple( this, RDF.li(1), o )
* @sec.triple Update Triples after index
* @throws UpdateDeniedException
* @throws DeleteDeniedException
* @throws AuthenticationRequiredException if user is not authenticated and is
* required to be.
*/
@Override
public SecuredSeq remove(final int index) throws UpdateDeniedException, DeleteDeniedException, AuthenticationRequiredException {
checkUpdate();
final RDFNode rdfNode = holder.getBaseItem().getObject(index);
if (rdfNode != null) {
checkDelete(new Triple(holder.getBaseItem().asNode(), RDF.li(index).asNode(), rdfNode.asNode()));
holder.getBaseItem().remove(index);
}
return holder.getSecuredItem();
}
use of org.apache.jena.rdf.model.RDFNode in project jena by apache.
the class SecuredRDFListTest method testAppendRDFList.
@Test
public void testAppendRDFList() {
final Set<Action> perms = SecurityEvaluator.Util.asSet(new Action[] { Action.Update, Action.Create });
Model m = ModelFactory.createDefaultModel();
RDFList lst = m.createList(newResource1, newResource2, newResource3, newResource4);
try {
SecuredRDFList actual = (SecuredRDFList) getSecuredRDFList().append(lst);
if (!securityEvaluator.evaluate(perms) || !shouldRead()) {
fail("Should have thrown AccessDeniedException");
}
Iterator<RDFNode> iter = ((RDFList) actual.getBaseItem()).iterator();
if (securityEvaluator.evaluate(Action.Read)) {
assertEquals(resource1, iter.next());
assertEquals(resource2, iter.next());
assertEquals(resource3, iter.next());
assertEquals(resource4, iter.next());
}
assertEquals(newResource1, iter.next());
assertEquals(newResource2, iter.next());
assertEquals(newResource3, iter.next());
assertEquals(newResource4, iter.next());
assertFalse(iter.hasNext());
} catch (final AccessDeniedException e) {
if (securityEvaluator.evaluate(perms) && shouldRead()) {
fail("Should not have thrown AccessDeniedException");
}
}
}
Aggregations