Package org.apache.clerezza.rdf.core

Examples of org.apache.clerezza.rdf.core.Resource


   
        // test if an entity (the topic) is referred (NOTE: in contrast to
        // fise:EntityAnnotations this property is NOT required - cardinality [0..*]
        Iterator<Triple> entityReferenceIterator = enhancements.filter(topicAnnotation,
                ENHANCER_ENTITY_REFERENCE, null);
        Resource expectedReferencedEntity = expectedValues.get(ENHANCER_ENTITY_REFERENCE);
        while(entityReferenceIterator.hasNext()){ //check possible multiple references
            Resource entityReferenceResource = entityReferenceIterator.next().getObject();
            // test if the reference is an URI
            assertTrue("fise:entity-reference value MUST BE of URIs",entityReferenceResource instanceof UriRef);
            if(expectedReferencedEntity != null && expectedReferencedEntity.equals(entityReferenceResource)){
                expectedReferencedEntity = null; //found
            }
        }
        assertNull("EntityAnnotation "+topicAnnotation+"fise:entity-reference has not the expected value "
                +expectedReferencedEntity+"!", expectedReferencedEntity);
       
        //test if the entity label is set (required)
        Iterator<Triple> entityLabelIterator = enhancements.filter(topicAnnotation, ENHANCER_ENTITY_LABEL, null);
        assertTrue(entityLabelIterator.hasNext());
        Resource expectedEntityLabel = expectedValues.get(ENHANCER_ENTITY_LABEL);
        while(entityLabelIterator.hasNext()){
            Resource entityLabelResource =  entityLabelIterator.next().getObject();
            assertTrue("fise:entity-label values MUST BE PlainLiterals (EntityAnnotation: "+topicAnnotation+")!",
                entityLabelResource instanceof PlainLiteral);
            if(expectedEntityLabel != null && expectedEntityLabel.equals(entityLabelResource)){
                expectedEntityLabel = null;
            }
        }
        assertNull("The expected EntityLabel "+expectedEntityLabel+" was not found",
            expectedEntityLabel);
       
        // test fise:entity-type(s). NOTE: this is not required - cardinality [0..*]
        Iterator<Triple> entityTypeIterator = enhancements.filter(topicAnnotation, Properties.ENHANCER_ENTITY_TYPE, null);
        Resource expectedEntityType = expectedValues.get(Properties.ENHANCER_ENTITY_TYPE);
        if(entityTypeIterator.hasNext()){
            Resource entityTypeResource = entityTypeIterator.next().getObject();
            assertTrue("fise:entity-type values MUST BE URIs",entityTypeResource instanceof UriRef);
            if(expectedEntityType != null && expectedEntityType.equals(entityTypeResource)){
                expectedEntityType = null; //found
            }
        }
View Full Code Here


    protected OWLOntologyID buildPublicKey(final UriRef resource) {
        // TODO desanitize?
        IRI oiri = null, viri = null;
        Iterator<Triple> it = meta.filter(resource, HAS_ONTOLOGY_IRI_URIREF, null);
        if (it.hasNext()) {
            Resource obj = it.next().getObject();
            if (obj instanceof UriRef) oiri = IRI.create(((UriRef) obj).getUnicodeString());
            else if (obj instanceof Literal) oiri = IRI.create(((Literal) obj).getLexicalForm());
        } else {
            // Anonymous ontology? Decode the resource itself (which is not null)
            return OntologyUtils.decode(resource.getUnicodeString());
        }
        it = meta.filter(resource, HAS_VERSION_IRI_URIREF, null);
        if (it.hasNext()) {
            Resource obj = it.next().getObject();
            if (obj instanceof UriRef) viri = IRI.create(((UriRef) obj).getUnicodeString());
            else if (obj instanceof Literal) viri = IRI.create(((Literal) obj).getLexicalForm());
        }
        if (viri == null) return new OWLOntologyID(oiri);
        else return new OWLOntologyID(oiri, viri);
View Full Code Here

        LiteralFactory lf = LiteralFactory.getInstance();
        TypedLiteral oiri = lf.createTypedLiteral(new UriRef(ontologyIri.toString()));
        TypedLiteral viri = versionIri == null ? null : lf.createTypedLiteral(new UriRef(versionIri
                .toString()));
        for (Iterator<Triple> it = meta.filter(null, HAS_ONTOLOGY_IRI_URIREF, oiri); it.hasNext();) {
            Resource subj = it.next().getSubject();
            log.debug(" -- Ontology IRI match found. Scanning");
            log.debug(" -- Resource : {}", subj);
            if (!(subj instanceof UriRef)) {
                log.debug(" ---- (uncomparable: skipping...)");
                continue;
View Full Code Here

                                                                                             + "/";

        // TODO check when not explicitly typed.
        SpaceType spaceType;
        if (meta.contains(new TripleImpl(candidate, RDF.type, SPACE_URIREF))) {
            Resource rScope;
            Iterator<Triple> parentSeeker = meta.filter(candidate, IS_SPACE_CORE_OF_URIREF, null);
            if (parentSeeker.hasNext()) {
                rScope = parentSeeker.next().getObject();
                spaceType = SpaceType.CORE;
            } else {
View Full Code Here

            aliases.add(dependent);
            for (OWLOntologyID depalias : aliases) {
                UriRef dep = buildResource(depalias);
                Iterator<Triple> it = meta.filter(dep, DEPENDS_ON_URIREF, null);
                while (it.hasNext()) {
                    Resource obj = it.next().getObject();
                    log.debug(" ... found {} (inverse).", obj);
                    if (obj instanceof UriRef) dependencies.add(buildPublicKey((UriRef) obj));
                    else log.warn(" ... Unexpected literal value!");
                }
                it = meta.filter(null, HAS_DEPENDENT_URIREF, dep);
                while (it.hasNext()) {
                    Resource sub = it.next().getSubject();
                    log.debug(" ... found {} (inverse).", sub);
                    if (sub instanceof UriRef) dependencies.add(buildPublicKey((UriRef) sub));
                    else log.warn(" ... Unexpected literal value!");
                }
            }
View Full Code Here

        UriRef dep = buildResource(dependency);
        log.debug("Getting depents for {}", dependency);
        synchronized (meta) {
            Iterator<Triple> it = meta.filter(null, DEPENDS_ON_URIREF, dep);
            while (it.hasNext()) {
                Resource sub = it.next().getSubject();
                log.debug(" ... found {} (inverse).", sub);
                if (sub instanceof UriRef) dependents.add(buildPublicKey((UriRef) sub));
                else log.warn(" ... Unexpected literal value!");
            }
            it = meta.filter(dep, HAS_DEPENDENT_URIREF, null);
            while (it.hasNext()) {
                Resource obj = it.next().getObject();
                log.debug(" ... found {} (inverse).", obj);
                if (obj instanceof UriRef) dependents.add(buildPublicKey((UriRef) obj));
                else log.warn(" ... Unexpected literal value!");
            }
        }
View Full Code Here

                else throw new InvalidMetaGraphStateException(
                        sub + " is not a valid ontology collector identifer.");
            }

            for (Iterator<Triple> it = meta.filter(ontologyId, IS_MANAGED_BY_URIREF, null); it.hasNext();) {
                Resource obj = it.next().getObject();
                if (obj instanceof UriRef) checkHandle((UriRef) obj, handles);
                else throw new InvalidMetaGraphStateException(
                        obj + " is not a valid ontology collector identifer.");
            }
        }
View Full Code Here

    @Override
    public Set<OWLOntologyID> getPublicKeys() {
        Set<OWLOntologyID> result = new HashSet<OWLOntologyID>();
        Iterator<Triple> it = meta.filter(null, RDF.type, ENTRY_URIREF);
        while (it.hasNext()) {
            Resource obj = it.next().getSubject();
            if (obj instanceof UriRef) result.add(buildPublicKey((UriRef) obj));
        }
        return result;
    }
View Full Code Here

    @Override
    public int getSize(OWLOntologyID publicKey) {
        UriRef subj = buildResource(publicKey);
        Iterator<Triple> it = meta.filter(subj, SIZE_IN_TRIPLES_URIREF, null);
        if (it.hasNext()) {
            Resource obj = it.next().getObject();
            if (obj instanceof Literal) {
                String s = ((Literal) obj).getLexicalForm();
                try {
                    return Integer.parseInt(s);
                } catch (Exception ex) {
View Full Code Here

                "Cannot locate aliases for null or anonymous public keys.");
        Set<OWLOntologyID> aliases = new HashSet<OWLOntologyID>();
        UriRef ont = buildResource(publicKey);
        // Forwards
        for (Iterator<Triple> it = meta.filter(ont, OWL.sameAs, null); it.hasNext();) {
            Resource r = it.next().getObject();
            if (r instanceof UriRef) aliases.add(buildPublicKey((UriRef) r));
        }
        // Backwards
        for (Iterator<Triple> it = meta.filter(null, OWL.sameAs, ont); it.hasNext();) {
            Resource r = it.next().getSubject();
            if (r instanceof UriRef) aliases.add(buildPublicKey((UriRef) r));
        }
        return aliases;
    }
View Full Code Here

TOP

Related Classes of org.apache.clerezza.rdf.core.Resource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.