org.apache.jena.sparql.function.FunctionRegistry Java Examples

The following examples show how to use org.apache.jena.sparql.function.FunctionRegistry. 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: SPARQLExtFunctionRegistry.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
public SPARQLExtFunctionRegistry(FunctionRegistry parent, Context context) {
    Iterator<String> uris = parent.keys();
    while (uris.hasNext()) {
        String uri = uris.next();
        registry.put(uri, parent.get(uri));
    }
    this.context = context;
}
 
Example #2
Source File: ContextUtils.java    From sparql-generate with Apache License 2.0 5 votes vote down vote up
private Builder() {
	this.context = new Context(ARQ.getContext());
	this.commons = new Commons();

	// update functionregistry
	FunctionRegistry registry = (FunctionRegistry) context.get(ARQConstants.registryFunctions);
	SPARQLExtFunctionRegistry newRegistry = new SPARQLExtFunctionRegistry(registry, context);
	context.set(ARQConstants.registryFunctions, newRegistry);

	// update iteratorregistry
	IteratorFunctionRegistry iteratorRegistry = (IteratorFunctionRegistry) context
			.get(SPARQLExt.REGISTRY_ITERATORS);
	IteratorFunctionRegistry newIteratorRegistry = new IteratorFunctionRegistry(iteratorRegistry, context);
	context.set(SPARQLExt.REGISTRY_ITERATORS, newIteratorRegistry);

	// default streammanager
	context.set(SysRIOT.sysStreamManager, SPARQLExtStreamManager.makeStreamManager());

	// set variable parts
	context.set(DATASET, DatasetFactory.create());

	// default prefix manager
	context.set(PREFIX_MANAGER, PrefixMapping.Standard);

	// default number of results and blank nodes
	context.set(SIZE, 0);
	// context.set(LIST_NODES, new HashMap<>());

	context.set(COMMONS, commons);
}
 
Example #3
Source File: SHACLFunctions.java    From shacl with Apache License 2.0 5 votes vote down vote up
/**
 * Registers a single SHACL function declared as a sh:Function.
 * @param resource  the function resource
 */
public static void registerFunction(Resource resource) {
	FunctionFactory arqFunction = DeclarativeFunctionDrivers.get().create(resource);
	if(arqFunction != null) {
		FunctionFactory oldFF = FunctionRegistry.get().get(resource.getURI());
		if(oldFF == null || oldFF instanceof DeclarativeFunctionFactory) {
			FunctionRegistry.get().put(resource.getURI(), arqFunction);
		}
	}
}
 
Example #4
Source File: SHACLFunctions.java    From shacl with Apache License 2.0 5 votes vote down vote up
private static void perhapsRegisterFunction(SHConstraintComponent component, Property predicate) {
	for(Resource validator : JenaUtil.getResourceProperties(component, predicate)) {
		if(validator.isURIResource() && 
				!FunctionRegistry.get().isRegistered(validator.getURI()) &&
				JenaUtil.hasIndirectType(validator, SH.SPARQLAskValidator)) {
			FunctionFactory arqFunction = new SHACLSPARQLARQFunction(component, validator);
			if(arqFunction != null) {
				FunctionRegistry.get().put(validator.getURI(), arqFunction);
			}
		}
	}
}
 
Example #5
Source File: SHFactory.java    From shacl with Apache License 2.0 5 votes vote down vote up
private static void init(Personality<RDFNode> p) {
p.add(SHConstraintComponent.class, new SimpleImplementation(SH.ConstraintComponent.asNode(), SHConstraintComponentImpl.class));
p.add(SHJSConstraint.class, new SimpleImplementation(SH.JSConstraint.asNode(), SHJSConstraintImpl.class));
p.add(SHJSExecutable.class, new SimpleImplementation(SH.JSExecutable.asNode(), SHJSExecutableImpl.class));
p.add(SHJSFunction.class, new SimpleImplementation(SH.JSFunction.asNode(), SHJSFunctionImpl.class));
  	p.add(SHParameter.class, new SimpleImplementation(SH.Parameter.asNode(), SHParameterImpl.class));
  	p.add(SHParameterizable.class, new SimpleImplementation(SH.Parameterizable.asNode(), SHParameterizableImpl.class));
  	p.add(SHParameterizableInstance.class, new SimpleImplementation(RDFS.Resource.asNode(), SHParameterizableInstanceImpl.class));
  	p.add(SHParameterizableTarget.class, new SimpleImplementation(SH.Target.asNode(), SHParameterizableTargetImpl.class));
  	p.add(SHPropertyShape.class, new SimpleImplementation(SH.PropertyShape.asNode(), SHPropertyShapeImpl.class));
  	p.add(SHResult.class, new SimpleImplementation(SH.AbstractResult.asNode(), SHResultImpl.class));
  	p.add(SHRule.class, new SimpleImplementation(SH.Rule.asNode(), SHRuleImpl.class));
  	p.add(SHNodeShape.class, new SimpleImplementation(SH.NodeShape.asNode(), SHNodeShapeImpl.class));
p.add(SHSPARQLConstraint.class, new SimpleImplementation(SH.SPARQLConstraint.asNode(), SHSPARQLConstraintImpl.class));
p.add(SHSPARQLFunction.class, new SimpleImplementation(SH.SPARQLFunction.asNode(), SHSPARQLFunctionImpl.class));
p.add(SHSPARQLTarget.class, new SimpleImplementation(SH.SPARQLTarget.asNode(), SHSPARQLTargetImpl.class));

FunctionRegistry.get().put(DASH.isDeactivated.getURI(), IsDeactivatedFunction.class);
FunctionRegistry.get().put(TOSH.hasShape.getURI(), HasShapeFunction.class);
FunctionRegistry.get().put(TOSH.isInTargetOf.getURI(), IsInTargetOfFunction.class);
FunctionRegistry.get().put("http://spinrdf.org/spif#checkRegexSyntax", CheckRegexSyntaxFunction.class);
FunctionRegistry.get().put("http://spinrdf.org/spif#isValidForDatatype", IsValidForDatatypeFunction.class);
FunctionRegistry.get().put("http://spinrdf.org/spif#isValidLangTag", IsValidLangTagFunction.class);
PropertyFunctionRegistry.get().put(TOSH.evalExpr.getURI(), EvalExprPFunction.class);
PropertyFunctionRegistry.get().put(TOSH.values.getURI(), ValuesPFunction.class);
PropertyFunctionRegistry.get().put(TOSH.targetContains.getURI(), TargetContainsPFunction.class);
  }
 
Example #6
Source File: FunctionsLoader.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
@Override
public void load(FunctionRegistry fnreg) {
    fnreg.put(FUN_JSONPath.URI, FUN_JSONPath.class);
    fnreg.put(FUN_CBOR.URI, FUN_CBOR.class);
}
 
Example #7
Source File: FunctionsLoader.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
@Override
public void load(FunctionRegistry fnreg) {
    fnreg.put(FUN_XPath.URI, FUN_XPath.class);
    fnreg.put(FUN_CSSPath.URI, FUN_CSSPath.class);
    fnreg.put(FUN_HTMLtoXML.URI, FUN_HTMLtoXML.class);
}
 
Example #8
Source File: FunctionsLoader.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
@Override
public void load(FunctionRegistry fnreg) {
    fnreg.put(FUN_GeoJSONGeometry.URI, FUN_GeoJSONGeometry.class);
}
 
Example #9
Source File: FunctionsLoader.java    From sparql-generate with Apache License 2.0 4 votes vote down vote up
@Override
public void load(FunctionRegistry fnreg) {
    fnreg.put(FUN_Markdown.URI, FUN_Markdown.class);
}
 
Example #10
Source File: CurrentThreadFunctionRegistry.java    From shacl with Apache License 2.0 4 votes vote down vote up
public CurrentThreadFunctionRegistry(FunctionRegistry base) {
	this.base = base;
}
 
Example #11
Source File: FunctionTestCaseType.java    From shacl with Apache License 2.0 4 votes vote down vote up
@Override
public void run(Model results) {
	Resource testCase = getResource();
	
	FunctionRegistry oldFR = FunctionRegistry.get();
	CurrentThreadFunctionRegistry threadFR = new CurrentThreadFunctionRegistry(oldFR);
	FunctionRegistry.set(ARQ.getContext(), threadFR);
	CurrentThreadFunctions old = CurrentThreadFunctionRegistry.register(testCase.getModel());

	try {
		for(TestCaseContextFactory contextFactory : contextFactories) {
			TestCaseContext context = contextFactory.createContext();
			String expression = JenaUtil.getStringProperty(testCase, DASH.expression);
			Statement expectedResultS = testCase.getProperty(DASH.expectedResult);
			String queryString = "SELECT (" + expression + " AS ?result) WHERE {}";
			Query query = ARQFactory.get().createQuery(testCase.getModel(), queryString);
			context.setUpTestContext();
			try(QueryExecution qexec = ARQFactory.get().createQueryExecution(query, testCase.getModel())) {
			    ResultSet rs = qexec.execSelect();
			    if(!rs.hasNext()) {
			        if(expectedResultS != null) {
			            createFailure(results,
			                          "Expression returned no result, but expected: " + expectedResultS.getObject(),
			                          context);
			            return;
			        }
			    }
			    else {
			        RDFNode actual = rs.next().get("result");
			        if(expectedResultS == null) {
			            if(actual != null) {
			                createFailure(results,
			                              "Expression returned a result, but none expected: " + actual, context);
			                return;
			            }
			        }
			        else if(testCase.hasProperty(DASH.expectedResultIsTTL, JenaDatatypes.TRUE)) {
			        	Graph expectedGraph = parseGraph(expectedResultS.getObject());
			        	Graph actualGraph = parseGraph(actual);
			        	if(!expectedGraph.isIsomorphicWith(actualGraph)) {
				            createFailure(results,
			                          "Mismatching result graphs. Expected: " + expectedResultS.getObject() + ". Found: " + actual, context);
				            return;
			        	}
			        }
			        else if(!expectedResultS.getObject().equals(actual)) {
			            createFailure(results,
			                          "Mismatching result. Expected: " + expectedResultS.getObject() + ". Found: " + actual, context);
			            return;
			        }
			    }
			}
			finally {
				context.tearDownTestContext();
			}
		}
	}
	finally {
		CurrentThreadFunctionRegistry.unregister(old);
		FunctionRegistry.set(ARQ.getContext(), oldFR);
	}
	
	createResult(results, DASH.SuccessTestCaseResult);
}
 
Example #12
Source File: JSTestCaseType.java    From shacl with Apache License 2.0 4 votes vote down vote up
@Override
public void run(Model results) {
	Resource testCase = getResource();
	
	FunctionRegistry oldFR = FunctionRegistry.get();
	CurrentThreadFunctionRegistry threadFR = new CurrentThreadFunctionRegistry(oldFR);
	FunctionRegistry.set(ARQ.getContext(), threadFR);

	CurrentThreadFunctions old = CurrentThreadFunctionRegistry.register(testCase.getModel());
	Statement expectedResultS = testCase.getProperty(DASH.expectedResult);
	String queryString = "SELECT (<" + getResource() + ">() AS ?result) WHERE {}";
	Query query = ARQFactory.get().createQuery(testCase.getModel(), queryString);
	try(QueryExecution qexec = ARQFactory.get().createQueryExecution(query, testCase.getModel())) {
	    ResultSet rs = qexec.execSelect();
	    if(!rs.hasNext()) {
	        if(expectedResultS != null) {
	            createFailure(results,
	                          "Expression returned no result, but expected: " + expectedResultS.getObject());
	            return;
	        }
	    }
	    else {
	        RDFNode result = rs.next().get("result");
	        if(expectedResultS == null) {
	            if(result != null) {
	                createFailure(results,
	                              "Expression returned a result, but none expected: " + result);
	                return;
	            }
	        }
	        else if(!expectedResultS.getObject().equals(result)) {
	            createFailure(results,
	                          "Mismatching result. Expected: " + expectedResultS.getObject() + ". Found: " + result);
	            return;
	        }
	    }
	}
	finally {
		CurrentThreadFunctionRegistry.unregister(old);
		FunctionRegistry.set(ARQ.getContext(), oldFR);
	}
	
	createResult(results, DASH.SuccessTestCaseResult);
}
 
Example #13
Source File: TarqlQuery.java    From tarql with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static void registerFunctions() {
	if (registered) return;
	registered = true;
	FunctionRegistry.get().put(ExpandPrefixFunction.IRI, ExpandPrefixFunction.class);
	FunctionRegistry.get().put(ExpandPrefixedNameFunction.IRI, ExpandPrefixedNameFunction.class);
}
 
Example #14
Source File: FunctionLoader.java    From sparql-generate with Apache License 2.0 votes vote down vote up
void load(FunctionRegistry fnreg);