Java Code Examples for org.apache.jena.rdf.model.Resource#getLocalName()

The following examples show how to use org.apache.jena.rdf.model.Resource#getLocalName() . 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: FunctionExpression.java    From shacl with Apache License 2.0 5 votes vote down vote up
public FunctionExpression(RDFNode expr, Resource function, List<NodeExpression> args) {
	
	super(expr);
	
	this.args = args;
	this.function = function;
	
	if(function.getNameSpace().equals(SPARQL.NS)) {
		ItemList il = new ItemList();
		il.add(function.asNode());
		for(int i = 0; i < args.size(); i++) {
			il.add(Var.alloc("a" + i));
		}
		BuilderExpr.Build build = bob.getBuild(function.getLocalName());
		if(build == null) {
			throw new IllegalArgumentException("Unknown SPARQL built-in " + function.getLocalName());
		}
		this.expr = build.make(il);
	}
	else {
		StringBuffer sb = new StringBuffer();
		sb.append("<");
		sb.append(function);
		sb.append(">(");
		for(int i = 0; i < args.size(); i++) {
			if(i > 0) {
				sb.append(",");
			}
			sb.append("?a" + i);
		}
		sb.append(")");
		this.expr = ExprUtils.parse(sb.toString());
	}
}
 
Example 2
Source File: JenaTransformationInjectSwitchSet.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void activate(final Collection<JenaSwitchSetInjectMatch> matches) {
	final Model model = driver.getModel();
	final Property currentPositionProperty = model.getProperty(BASE_PREFIX + CURRENTPOSITION);

	for (final JenaSwitchSetInjectMatch match : matches) {
		final Resource sw = match.getSw();
		
		final Selector selector = new SimpleSelector(sw, currentPositionProperty, (RDFNode) null);
		final StmtIterator statementsToRemove = model.listStatements(selector);
		if (!statementsToRemove.hasNext()) {
			continue;

		}

		// delete old statement
		final Statement oldStatement = statementsToRemove.next();
		model.remove(oldStatement);

		// get next enum value
		final Resource currentPositionResource = oldStatement.getObject().asResource();
		final String currentPositionRDFString = currentPositionResource.getLocalName();
		final String currentPositionString = RdfHelper.removePrefix(Position.class, currentPositionRDFString);
		final Position currentPosition = Position.valueOf(currentPositionString);
		final Position newCurrentPosition = Position.values()[(currentPosition.ordinal() + 1) % Position.values().length];
		final String newCurrentPositionString = RdfHelper.addEnumPrefix(newCurrentPosition);
		final Resource newCurrentPositionResource = model.createResource(BASE_PREFIX + newCurrentPositionString);

		// set new value
		final Statement newStatement = model.createLiteralStatement(sw, currentPositionProperty, newCurrentPositionResource);
		model.add(newStatement);

	}
}
 
Example 3
Source File: TestGeneratorImpl.java    From RDFUnit with Apache License 2.0 5 votes vote down vote up
@Builder
private TestGeneratorImpl(Resource element, String description, String query, Pattern pattern, Collection<ResultAnnotation> generatorAnnotations) {

    this.element = checkNotNull(element);
    String tagName = element.getLocalName();

    this.description = checkNotNull(description, "Description in %s should not be null", tagName);
    this.query = checkNotNull(query, "Query in %s should not be null", tagName);
    checkState(!query.trim().isEmpty(), "Query in %s should not be empty", tagName);
    this.pattern = checkNotNull(pattern, "Pattern in %s should not be null", tagName);
    this.annotations = ImmutableList.copyOf(checkNotNull(generatorAnnotations));
}