Java Code Examples for org.eclipse.rdf4j.model.IRI#getNamespace()

The following examples show how to use org.eclipse.rdf4j.model.IRI#getNamespace() . 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: TransitivePropertyVisitor.java    From rya with Apache License 2.0 6 votes vote down vote up
@Override
protected void meetSP(final StatementPattern node) throws Exception {
    final StatementPattern sp = node.clone();
    final Var predVar = sp.getPredicateVar();

    final IRI pred = (IRI) predVar.getValue();
    final String predNamespace = pred.getNamespace();

    final Var objVar = sp.getObjectVar();
    final Var cntxtVar = sp.getContextVar();
    if (objVar != null &&
            !RDF.NAMESPACE.equals(predNamespace) &&
            !SESAME.NAMESPACE.equals(predNamespace) &&
            !RDFS.NAMESPACE.equals(predNamespace)
            && !EXPANDED.equals(cntxtVar)) {

        final IRI transPropIri = (IRI) predVar.getValue();
        if (inferenceEngine.isTransitiveProperty(transPropIri)) {
            node.replaceWith(new TransitivePropertySP(sp.getSubjectVar(), sp.getPredicateVar(), sp.getObjectVar(), sp.getContextVar()));
        }
    }
}
 
Example 2
Source File: MemURITest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void compareURIs(String uri) throws Exception {
	IRI uriImpl = SimpleValueFactory.getInstance().createIRI(uri);
	MemIRI memURI = new MemIRI(this, uriImpl.getNamespace(), uriImpl.getLocalName());

	assertEquals("MemURI not equal to URIImpl for: " + uri, uriImpl, memURI);
	assertEquals("MemURI has different hash code than URIImpl for: " + uri, uriImpl.hashCode(), memURI.hashCode());
}
 
Example 3
Source File: BinaryQueryResultWriter.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void writeQName(IRI uri) throws IOException {
	// Check if the URI has a new namespace
	String namespace = uri.getNamespace();

	Integer nsID = namespaceTable.get(namespace);

	if (nsID == null) {
		// Generate a ID for this new namespace
		nsID = writeNamespace(namespace);
	}

	out.writeByte(QNAME_RECORD_MARKER);
	out.writeInt(nsID.intValue());
	writeString(uri.getLocalName());
}
 
Example 4
Source File: BinaryQueryResultWriter.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void writeLiteral(Literal literal) throws IOException {
	String label = literal.getLabel();
	IRI datatype = literal.getDatatype();

	int marker = PLAIN_LITERAL_RECORD_MARKER;

	if (Literals.isLanguageLiteral(literal)) {
		marker = LANG_LITERAL_RECORD_MARKER;
	} else {
		String namespace = datatype.getNamespace();

		if (!namespaceTable.containsKey(namespace)) {
			// Assign an ID to this new namespace
			writeNamespace(namespace);
		}

		marker = DATATYPE_LITERAL_RECORD_MARKER;
	}

	out.writeByte(marker);
	writeString(label);

	if (Literals.isLanguageLiteral(literal)) {
		writeString(literal.getLanguage().get());
	} else {
		writeQName(datatype);
	}
}
 
Example 5
Source File: InverseOfVisitor.java    From rya with Apache License 2.0 5 votes vote down vote up
@Override
protected void meetSP(StatementPattern node) throws Exception {
    StatementPattern sp = node.clone();
    final Var predVar = sp.getPredicateVar();

    IRI pred = (IRI) predVar.getValue();
    String predNamespace = pred.getNamespace();

    final Var objVar = sp.getObjectVar();
    final Var cntxtVar = sp.getContextVar();
    if (objVar != null &&
            !RDF.NAMESPACE.equals(predNamespace) &&
            !SESAME.NAMESPACE.equals(predNamespace) &&
            !RDFS.NAMESPACE.equals(predNamespace)
            && !EXPANDED.equals(cntxtVar)) {
        /**
         *
         * { ?a ?pred ?b .}\n" +
         "       UNION " +
         "      { ?b ?pred ?a }
         */

        IRI predIri = (IRI) predVar.getValue();
        IRI invPropIri = inferenceEngine.findInverseOf(predIri);
        if (invPropIri != null) {
            Var subjVar = sp.getSubjectVar();
            Union union = new InferUnion();
            union.setLeftArg(sp);
            union.setRightArg(new StatementPattern(objVar, new Var(predVar.getName(), invPropIri), subjVar, cntxtVar));
            node.replaceWith(union);
        }
    }
}
 
Example 6
Source File: SymmetricPropertyVisitor.java    From rya with Apache License 2.0 5 votes vote down vote up
@Override
protected void meetSP(StatementPattern node) throws Exception {
    StatementPattern sp = node.clone();

    final Var predVar = sp.getPredicateVar();
    IRI pred = (IRI) predVar.getValue();
    String predNamespace = pred.getNamespace();

    final Var objVar = sp.getObjectVar();
    final Var cntxtVar = sp.getContextVar();
    if (objVar != null &&
            !RDF.NAMESPACE.equals(predNamespace) &&
            !SESAME.NAMESPACE.equals(predNamespace) &&
            !RDFS.NAMESPACE.equals(predNamespace)
            && !EXPANDED.equals(cntxtVar)) {
        /**
         *
         * { ?a ?pred ?b .}\n" +
         "       UNION " +
         "      { ?b ?pred ?a }
         */

        IRI symmPropIri = (IRI) predVar.getValue();
        if(inferenceEngine.isSymmetricProperty(symmPropIri)) {
            Var subjVar = sp.getSubjectVar();
            Union union = new InferUnion();
            union.setLeftArg(sp);
            union.setRightArg(new StatementPattern(objVar, predVar, subjVar, cntxtVar));
            node.replaceWith(union);
        }
    }
}
 
Example 7
Source File: SubPropertyOfVisitor.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
    protected void meetSP(final StatementPattern node) throws Exception {
        final StatementPattern sp = node.clone();
        final Var predVar = sp.getPredicateVar();

        final IRI pred = (IRI) predVar.getValue();
        final String predNamespace = pred.getNamespace();

        final Var objVar = sp.getObjectVar();
        final Var cntxtVar = sp.getContextVar();
        if (objVar != null &&
                !RDF.NAMESPACE.equals(predNamespace) &&
                !SESAME.NAMESPACE.equals(predNamespace) &&
                !RDFS.NAMESPACE.equals(predNamespace)
                && !EXPANDED.equals(cntxtVar)) {
            /**
             *
             * { ?subProp rdfs:subPropertyOf ub:worksFor . ?y ?subProp <http://www.Department0.University0.edu> }\n" +
             "       UNION " +
             "      { ?y ub:worksFor <http://www.Department0.University0.edu> }
             */
//            String s = UUID.randomUUID().toString();
//            Var subPropVar = new Var(s);
//            StatementPattern subPropOf = new StatementPattern(subPropVar, new Var("c-" + s, SESAME.DIRECTSUBPROPERTYOF), predVar, EXPANDED);
//            StatementPattern subPropOf2 = new StatementPattern(sp.getSubjectVar(), subPropVar, objVar, EXPANDED);
//            InferJoin join = new InferJoin(subPropOf, subPropOf2);
//            join.getProperties().put(InferConstants.INFERRED, InferConstants.TRUE);
//            node.replaceWith(join);

//            Collection<URI> parents = inferenceEngine.findParents(inferenceEngine.subPropertyOfGraph, (URI) predVar.getValue());
//            if (parents != null && parents.size() > 0) {
//                StatementPatterns statementPatterns = new StatementPatterns();
//                statementPatterns.patterns.add(node);
//                Var subjVar = node.getSubjectVar();
//                for (IRI iri : parents) {
//                    statementPatterns.patterns.add(new StatementPattern(subjVar, new Var(predVar.getName(), iri), objVar));
//                }
//                node.replaceWith(statementPatterns);
//            }
//            if (parents != null && parents.size() > 0) {
//                VarCollection vc = new VarCollection();
//                vc.setName(predVar.getName());
//                vc.values.add(predVar);
//                for (IRI iri : parents) {
//                    vc.values.add(new Var(predVar.getName(), iri));
//                }
//                Var subjVar = node.getSubjectVar();
//                node.replaceWith(new StatementPattern(subjVar, vc, objVar, node.getContextVar()));
//            }

            final IRI subprop_iri = (IRI) predVar.getValue();
            final Set<IRI> parents = InferenceEngine.findParents(inferenceEngine.getSubPropertyOfGraph(), subprop_iri);
            if (parents != null && parents.size() > 0) {
                final String s = UUID.randomUUID().toString();
                final Var typeVar = new Var(s);
                final FixedStatementPattern fsp = new FixedStatementPattern(typeVar, new Var("c-" + s, RDFS.SUBPROPERTYOF), predVar, cntxtVar);
//                fsp.statements.add(new NullableStatementImpl(subprop_uri, RDFS.SUBPROPERTYOF, subprop_uri));
                //add self
                parents.add(subprop_iri);
                for (final IRI u : parents) {
                    fsp.statements.add(new NullableStatementImpl(u, RDFS.SUBPROPERTYOF, subprop_iri));
                }

                final StatementPattern rdfType = new DoNotExpandSP(sp.getSubjectVar(), typeVar, sp.getObjectVar(), cntxtVar);
                final InferJoin join = new InferJoin(fsp, rdfType);
                join.getProperties().put(InferConstants.INFERRED, InferConstants.TRUE);
                node.replaceWith(join);
            }
        }
    }