Java Code Examples for org.openrdf.model.URI#getLocalName()

The following examples show how to use org.openrdf.model.URI#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: ObjectRepositoryConfig.java    From anno4j with Apache License 2.0 6 votes vote down vote up
private Class<?> loadClass(Value base) throws ObjectStoreConfigException {
	if (base instanceof URI) {
		URI uri = (URI) base;
		if (JAVA_NS.equals(uri.getNamespace())) {
			String name = uri.getLocalName();
			try {
				synchronized (cl) {
					return Class.forName(name, true, cl);
				}
			} catch (ClassNotFoundException e) {
				throw new ObjectStoreConfigException(e);
			}
		}
	}
	throw new ObjectStoreConfigException("Invalid java URI: " + base);
}
 
Example 2
Source File: SesameTransformationInjectSwitchSet.java    From trainbenchmark with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void activate(final Collection<SesameSwitchSetInjectMatch> matches) throws RepositoryException {
	final RepositoryConnection con = driver.getConnection();
	final ValueFactory vf = driver.getValueFactory();

	final URI currentPositionProperty = vf.createURI(BASE_PREFIX + CURRENTPOSITION);

	for (final SesameSwitchSetInjectMatch match : matches) {
		final URI sw = match.getSw();
		final RepositoryResult<Statement> statements = con.getStatements(sw, currentPositionProperty, null, true);
		if (!statements.hasNext()) {
			continue;
		}

		final Statement oldStatement = statements.next();

		// delete old statement
		con.remove(oldStatement);

		// get next enum value
		final URI currentPositionURI = (URI) oldStatement.getObject();
		final String currentPositionRDFString = currentPositionURI.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 URI newCurrentPositionUri = vf.createURI(BASE_PREFIX + newCurrentPositionString);

		// set new value
		con.add(sw, currentPositionProperty, newCurrentPositionUri);
	}
}
 
Example 3
Source File: JavaNameResolver.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public String getMethodName(URI name) {
	String ns = name.getNamespace();
	String localPart = name.getLocalName();
	if (prefixes.containsKey(ns))
		return word(getMemberPrefix(ns) + initcap(localPart));
	return word(localPart);
}
 
Example 4
Source File: JavaNameResolver.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public String getPluralParameterName(URI name) {
	String ns = name.getNamespace();
	String localPart = name.getLocalName();
	String plural = plural(localPart);
	if (model.contains(new URIImpl(ns + plural), null, null)) {
		plural = localPart;
	}
	return word(plural);
}
 
Example 5
Source File: JavaNameResolver.java    From anno4j with Apache License 2.0 5 votes vote down vote up
public String getPluralPropertyName(URI name) {
	String ns = name.getNamespace();
	String localPart = name.getLocalName();
	String plural = plural(localPart);
	if (model.contains(new URIImpl(ns + plural), null, null)) {
		plural = localPart;
	}
	if (prefixes.containsKey(ns))
		return getMemberPrefix(ns) + initcap(plural);
	return enc(plural);
}
 
Example 6
Source File: JavaNameResolver.java    From anno4j with Apache License 2.0 5 votes vote down vote up
private String getMemberName(URI name) {
	String ns = name.getNamespace();
	String localPart = name.getLocalName();
	if (prefixes.containsKey(ns))
		return getMemberPrefix(ns) + initcap(localPart);
	return enc(localPart);
}
 
Example 7
Source File: RDFClass.java    From anno4j with Apache License 2.0 5 votes vote down vote up
private void constants(JavaMessageBuilder builder) {
	List<? extends Value> oneOf = this.getList(OWL.ONEOF);
	if (oneOf != null) {
		Map<String, URI> names = new LinkedHashMap<String, URI>();
		for (Value one : oneOf) {
			if (one instanceof URI) {
				URI uri = (URI) one;
				String localPart = uri.getLocalName();
				if (localPart.length() < 1) {
					localPart = uri.stringValue();
				}
				String name = localPart.replaceAll("^[^a-zA-Z]", "_")
						.replaceAll("\\W+", "_");
				if (names.containsKey(name)) {
					int count = 1;
					while (names.containsKey(name + '_' + count)) {
						count++;
					}
					name = name + '_' + count;
				}
				names.put(name, uri);
			}
		}
		if (!names.isEmpty()) {
			names = toUpperCase(names);
			for (Map.Entry<String, URI> e : names.entrySet()) {
				builder.staticURIField(e.getKey(), e.getValue());
			}
			if (!names.containsKey("ONEOF")) {
				builder.staticURIArrayField("ONEOF", names.keySet());
			}
		}
	}
}
 
Example 8
Source File: BigdataEdge.java    From database with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String toString() {
    
    final URI s = (URI) stmt.getSubject();
    final URI p = (URI) stmt.getPredicate();
    final URI o = (URI) stmt.getObject();
    return "e["+p.getLocalName()+"]["+s.getLocalName()+"->"+o.getLocalName()+"]";
    
}
 
Example 9
Source File: StdSubjectMap.java    From GeoTriples with Apache License 2.0 5 votes vote down vote up
public String toString() {
	String result = super.toString() + " [StdSubjectMap : classIRIs = [";
	for (URI uri : classIRIs)
		result += uri.getLocalName() + ",";
	result += "], graphMaps = [";
	for (GraphMap graphMap : graphMaps)
		result += graphMap + ",";
	result += "]]";
	return result;
}
 
Example 10
Source File: OwlNormalizer.java    From anno4j with Apache License 2.0 4 votes vote down vote up
private URI nameAnonymous(Resource clazz) {
	for (Value eq : ds.match(clazz, OWL.EQUIVALENTCLASS, null).objects()) {
		if (eq instanceof URI) {
			nameClass(clazz, (URI) eq);
			return (URI) eq;
		}
	}
	Resource unionOf = ds.match(clazz, OWL.UNIONOF, null).objectResource();
	if (unionOf != null) {
		return renameClass("", clazz, "Or", new RDFList(ds, unionOf)
				.asList());
	}
	Resource intersectionOf = ds.match(clazz, OWL.INTERSECTIONOF, null)
			.objectResource();
	if (intersectionOf != null) {
		return renameClass("", clazz, "And", new RDFList(ds,
				intersectionOf).asList());
	}
	Resource oneOf = ds.match(clazz, OWL.ONEOF, null).objectResource();
	if (oneOf != null) {
		return renameClass("Is", clazz, "Or", new RDFList(ds, oneOf)
				.asList());
	}
	Resource complement = ds.match(clazz, OWL.COMPLEMENTOF, null)
			.objectResource();
	if (complement != null) {
		URI comp = complement instanceof URI ? (URI) complement : null;
		if (comp == null) {
			comp = nameAnonymous(complement);
			if (comp == null)
				return null;
		}
		String name = "Not" + comp.getLocalName();
		URI uri = new URIImpl(comp.getNamespace() + name);
		nameClass(clazz, uri);
		return uri;
	}
	if (ds.contains(clazz, MSG.MATCHING, null)) {
		return renameClass("", clazz, "Or", ds.match(clazz, MSG.MATCHING, null)
				.objects());
	}
	return null;
}
 
Example 11
Source File: JavaAnnotationBuilder.java    From anno4j with Apache License 2.0 4 votes vote down vote up
public String getClassName(URI name) throws ObjectStoreConfigException {
	if (JAVA_NS.equals(name.getNamespace()))
		return name.getLocalName();
	return resolver.getClassName(name);
}
 
Example 12
Source File: AST2SPARQLUtil.java    From database with GNU General Public License v2.0 4 votes vote down vote up
public String toExternal(final URI uri) {

        if (prefixDecls != null) {

            final String prefix = namespaces.get(uri.getNamespace());

            if (prefix != null) {

                return prefix + ":" + uri.getLocalName();

            }

        }

        return "<" + uri.stringValue() + ">";

    }
 
Example 13
Source File: TestURIExtensionIV.java    From database with GNU General Public License v2.0 4 votes vote down vote up
private URIExtensionIV<BigdataURI> newFixture(final URI uri) {

        final String namespace = uri.getNamespace();

        final URI namespaceURI = new URIImpl(namespace);
        
        final IV<?, ?> namespaceIV = vocab.get(namespaceURI);

        if (namespaceIV == null) {

            fail("Not declared by vocabulary: namespace: " + namespace);
            
        }
        
        final FullyInlineTypedLiteralIV<BigdataLiteral> localNameIV = new FullyInlineTypedLiteralIV<BigdataLiteral>(
                uri.getLocalName());

        final URIExtensionIV<BigdataURI> iv = new URIExtensionIV<BigdataURI>(
                localNameIV, namespaceIV);
        
        return iv;
        
    }
 
Example 14
Source File: AbstractTripleStore.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Substitutes in well know namespaces (rdf, rdfs, etc).
 */
final private String abbrev(final URI uri) {

    final String uriString = uri.toString();

    // final int index = uriString.lastIndexOf('#');
    //        
    // if(index==-1) return uriString;
    //
    // final String namespace = uriString.substring(0, index);

    final String namespace = uri.getNamespace();

    final String prefix = uriToPrefix.get(namespace);

    if (prefix != null) {

        return prefix + ":" + uri.getLocalName();

    }
    
    return uriString;

}