Examples of JsonLdResource


Examples of org.apache.stanbol.commons.jsonld.JsonLdResource

        jsonLd.setNamespacePrefixMap(this.namespacePrefixMap);
        jsonLd.setUseTypeCoercion(this.useTypeCoercion);

        Map<NonLiteral, String> subjects = createSubjectsMap(tc);
        for (NonLiteral subject : subjects.keySet()) {
            JsonLdResource resource = new JsonLdResource();
           
            String strSubject = subject.toString();
            if (subject instanceof UriRef) {
                UriRef uri = (UriRef) subject;
                strSubject = uri.getUnicodeString();
            }
            resource.setSubject(strSubject);

            Iterator<Triple> triplesFromSubject = tc.filter(subject, null, null);
            while (triplesFromSubject.hasNext()) {
                Triple currentTriple = triplesFromSubject.next();
                if (currentTriple.getPredicate().getUnicodeString().equals(RDF_NS_TYPE)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("serialize() adding rdf:type: \"a\":" + currentTriple.getObject());
                    }
                    resource.addType(((UriRef) currentTriple.getObject()).getUnicodeString());
                } else {
                    if (logger.isDebugEnabled()) {
                        logger.debug("serializer() adding predicate " + currentTriple.getPredicate().toString() + " with object " + currentTriple.getObject().toString());
                    }

                    String property = currentTriple.getPredicate().getUnicodeString();
                    JsonLdProperty jldProperty = resource.getProperty(property);
                    if (jldProperty == null) {
                        jldProperty = new JsonLdProperty(property);
                    }
                   
                    String strValue = currentTriple.getObject().toString();
                    JsonLdPropertyValue jldValue = new JsonLdPropertyValue();

                    if (currentTriple.getObject() instanceof PlainLiteral) {
                        PlainLiteral plain = (PlainLiteral) currentTriple.getObject();
                        if (plain.getLanguage() != null) {
                            jldValue.setLanguage(plain.getLanguage().toString());
                        }
                        strValue = plain.getLexicalForm();
                    }
                    else if (currentTriple.getObject() instanceof TypedLiteral) {
                        TypedLiteral typedObject = (TypedLiteral) currentTriple.getObject();
                        String type = typedObject.getDataType().getUnicodeString();
                        jldValue.setType(type);
                        strValue = typedObject.getLexicalForm();
                    }
                    else if (currentTriple.getObject() instanceof UriRef) {
                        UriRef uriRef = (UriRef) currentTriple.getObject();
                        jldValue.setType(JsonLdCommon.ID);
                        strValue = uriRef.getUnicodeString();
                    }
                   
                    jldValue.setValue(convertValueType(strValue));
                    jldProperty.addValue(jldValue);
                    resource.putProperty(jldProperty);
                }
            }

            jsonLd.put(resource.getSubject(), resource);
        }

        try {
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(serializedGraph,"utf-8"));
            writer.write(jsonLd.toString(this.indentation));
View Full Code Here

Examples of org.apache.stanbol.commons.jsonld.JsonLdResource

        jsonLd.setNamespacePrefixMap(this.namespacePrefixMap);
        jsonLd.setUseTypeCoercion(this.useTypeCoercion);

        Map<NonLiteral, String> subjects = createSubjectsMap(tc);
        for (NonLiteral subject : subjects.keySet()) {
            JsonLdResource resource = new JsonLdResource();
           
            String strSubject = subject.toString();
            if (subject instanceof UriRef) {
                UriRef uri = (UriRef) subject;
                strSubject = uri.getUnicodeString();
            }
            resource.setSubject(strSubject);

            Iterator<Triple> triplesFromSubject = tc.filter(subject, null, null);
            while (triplesFromSubject.hasNext()) {
                Triple currentTriple = triplesFromSubject.next();
                if (currentTriple.getPredicate().getUnicodeString().equals(RDF_NS_TYPE)) {
                    if (logger.isDebugEnabled()) {
                        logger.debug("serialize() adding rdf:type: \"a\":" + currentTriple.getObject());
                    }
                    resource.addType(((UriRef) currentTriple.getObject()).getUnicodeString());
                } else {
                    if (logger.isDebugEnabled()) {
                        logger.debug("serializer() adding predicate " + currentTriple.getPredicate().toString() + " with object " + currentTriple.getObject().toString());
                    }

                    String property = currentTriple.getPredicate().getUnicodeString();
                    JsonLdProperty jldProperty = resource.getProperty(property);
                    if (jldProperty == null) {
                        jldProperty = new JsonLdProperty(property);
                    }
                   
                    String strValue = currentTriple.getObject().toString();
                    JsonLdPropertyValue jldValue = new JsonLdPropertyValue();

                    if (currentTriple.getObject() instanceof PlainLiteral) {
                        PlainLiteral plain = (PlainLiteral) currentTriple.getObject();
                        if (plain.getLanguage() != null) {
                            jldValue.setLanguage(plain.getLanguage().toString());
                        }
                        strValue = plain.getLexicalForm();
                    }
                    else if (currentTriple.getObject() instanceof TypedLiteral) {
                        TypedLiteral typedObject = (TypedLiteral) currentTriple.getObject();
                        String type = typedObject.getDataType().getUnicodeString();
                        jldValue.setType(type);
                        strValue = typedObject.getLexicalForm();
                    }
                    else if (currentTriple.getObject() instanceof UriRef) {
                        UriRef uriRef = (UriRef) currentTriple.getObject();
                        jldValue.setType(JsonLdCommon.ID);
                        strValue = uriRef.getUnicodeString();
                    }
                   
                    jldValue.setValue(convertValueType(strValue));
                    jldProperty.addValue(jldValue);
                    resource.putProperty(jldProperty);
                }
            }

            jsonLd.put(resource.getSubject(), resource);
        }

        try {
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(serializedGraph,"utf-8"));
            writer.write(jsonLd.toString(this.indentation));
View Full Code Here

Examples of org.apache.stanbol.commons.jsonld.JsonLdResource

    }

    public JsonLd factToJsonLd() {
        JsonLd jsonLd = new JsonLd();
       
        JsonLdResource subject = new JsonLdResource();
        subject.setProfile(this.factSchemaURN);
        for (String role : this.roleMap.keySet()) {
            subject.putProperty(role, this.roleMap.get(role));
        }
        jsonLd.put(subject);
       
        return jsonLd;
    }
View Full Code Here

Examples of org.apache.stanbol.commons.jsonld.JsonLdResource

    JsonLd root = new JsonLd();
    if (rows != null && !rows.isEmpty()) {
        int rowCount = 0;
      for (FactResult result : rows) {
          rowCount++;
          JsonLdResource subject = new JsonLdResource();
          subject.setSubject("R" + rowCount);
        for (int i = 0; i < header.size(); i++) {
          subject.putProperty(header.get(i), result.getValues().get(i));
        }
        root.put(subject);
      }
    }
View Full Code Here

Examples of org.apache.stanbol.commons.jsonld.JsonLdResource

    public void testFactFromJsonLd() {
        JsonLd jsonLd = new JsonLd();
        jsonLd.addNamespacePrefix("http://iks-project.eu/ont/", "iks");
        jsonLd.addNamespacePrefix("http://upb.de/persons/", "upb");
       
        JsonLdResource factResource = new JsonLdResource();
        factResource.setProfile("iks:employeeOf");
        factResource.putProperty("person", new JsonLdIRI("upb:bnagel"));
        factResource.putProperty("organization", new JsonLdIRI("http://uni-paderborn.de"));
        jsonLd.put(factResource);
       
        Fact fact = Fact.factFromJsonLd(jsonLd);
        assertEquals("http://iks-project.eu/ont/employeeOf", fact.getFactSchemaURN());
        assertEquals(2, fact.getRoles().size());
View Full Code Here

Examples of org.apache.stanbol.commons.jsonld.JsonLdResource

    public void testFactFromJsonLdMultiFacts() {
        JsonLd jsonLd = new JsonLd();
        jsonLd.addNamespacePrefix("http://iks-project.eu/ont/", "iks");
        jsonLd.addNamespacePrefix("http://upb.de/persons/", "upb");
       
        JsonLdResource fact1Resource = new JsonLdResource();
        fact1Resource.setSubject("fact1");
        fact1Resource.setProfile("iks:employeeOf");
        fact1Resource.putProperty("person", new JsonLdIRI("upb:bnagel"));
        fact1Resource.putProperty("organization", new JsonLdIRI("http://uni-paderborn.de"));
        jsonLd.put(fact1Resource);

        JsonLdResource fact2Resource = new JsonLdResource();
        fact2Resource.setSubject("fact2");
        fact2Resource.setProfile("iks:employeeOf");
        fact2Resource.putProperty("person", new JsonLdIRI("upb:fchrist"));
        fact2Resource.putProperty("organization", new JsonLdIRI("http://uni-paderborn.de"));
        jsonLd.put(fact2Resource);
       
        Fact fact = Fact.factFromJsonLd(jsonLd);
        assertNull(fact);
    }
View Full Code Here

Examples of org.apache.stanbol.commons.jsonld.JsonLdResource

    public void testFactsFromJsonLdMultiFacts() {
        JsonLd jsonLd = new JsonLd();
        jsonLd.addNamespacePrefix("http://iks-project.eu/ont/", "iks");
        jsonLd.addNamespacePrefix("http://upb.de/persons/", "upb");
       
        JsonLdResource fact1Resource = new JsonLdResource();
        fact1Resource.setSubject("fact1");
        fact1Resource.setProfile("iks:employeeOf");
        fact1Resource.putProperty("person", new JsonLdIRI("upb:bnagel"));
        fact1Resource.putProperty("organization", new JsonLdIRI("http://uni-paderborn.de"));
        jsonLd.put(fact1Resource);

        JsonLdResource fact2Resource = new JsonLdResource();
        fact2Resource.setSubject("fact2");
        fact2Resource.setProfile("iks:employeeOf");
        fact2Resource.putProperty("person", new JsonLdIRI("upb:fchrist"));
        fact2Resource.putProperty("organization", new JsonLdIRI("http://uni-paderborn.de"));
        jsonLd.put(fact2Resource);
       
        Set<Fact> facts = Fact.factsFromJsonLd(jsonLd);
        assertNotNull(facts);
        assertEquals(2, facts.size());
View Full Code Here

Examples of org.apache.stanbol.commons.jsonld.JsonLdResource

    public void testFactsFromJsonLdMultiFactsMultiSchema() {
        JsonLd jsonLd = new JsonLd();
        jsonLd.addNamespacePrefix("http://iks-project.eu/ont/", "iks");
        jsonLd.addNamespacePrefix("http://upb.de/persons/", "upb");
       
        JsonLdResource fact1Resource = new JsonLdResource();
        fact1Resource.setSubject("fact1");
        fact1Resource.setProfile("iks:employeeOf");
        fact1Resource.putProperty("person", new JsonLdIRI("upb:bnagel"));
        fact1Resource.putProperty("organization", new JsonLdIRI("http://uni-paderborn.de"));
        jsonLd.put(fact1Resource);

        JsonLdResource fact2Resource = new JsonLdResource();
        fact2Resource.setSubject("fact2");
        fact2Resource.setProfile("iks:friendOf");
        fact2Resource.putProperty("person", new JsonLdIRI("upb:bnagel"));
        fact2Resource.putProperty("friend", new JsonLdIRI("upb:fchrist"));
        jsonLd.put(fact2Resource);
       
        Set<Fact> facts = Fact.factsFromJsonLd(jsonLd);
        assertNotNull(facts);
        assertEquals(2, facts.size());
View Full Code Here

Examples of org.apache.stanbol.commons.jsonld.JsonLdResource

    public static Query toQueryFromJsonLd(JsonLd jsonLdQuery) throws Exception {
        Query query = null;
        if (jsonLdQuery != null) {
            if (jsonLdQuery.getResourceSubjects() != null) {
                if (jsonLdQuery.getResourceSubjects().size() == 1) {
                    JsonLdResource subject = jsonLdQuery.getResource(jsonLdQuery.getResourceSubjects()
                            .iterator().next());
                    if (subject.hasPropertyIgnorecase(SELECT)) {
                        if (subject.hasPropertyIgnorecase(FROM)) {
                            if (subject.hasPropertyIgnorecase(WHERE)) {
                                query = new Query();
                                handleSelect(subject, query);
                                handleFrom(jsonLdQuery, subject, query);
                                handleWhere(jsonLdQuery, subject, query);
                            }
View Full Code Here

Examples of org.apache.stanbol.commons.jsonld.JsonLdResource

    @Test
    public void testToQueryFromJsonLd() throws Exception {
        JsonLd jldq = new JsonLd();
        jldq.addNamespacePrefix("http://iks-project.eu/ont/", "iks");
       
        JsonLdResource subject = new JsonLdResource();
        List<String> select = new ArrayList<String>();
        select.add("person");
        subject.putProperty("select", select);
        subject.putProperty("from", "iks:employeeOf");

        Map<String, Object> orga = new HashMap<String, Object>();
        orga.put("organization", new JsonLdIRI("http://upb.de"));

        Map<String, Object> eq = new HashMap<String, Object>();
        eq.put("=", orga);
       
        List<Object> where = new ArrayList<Object>();
        where.add(eq);
       
        subject.putProperty("where", where);
       
        jldq.put(subject);
       
        Query query = Query.toQueryFromJsonLd(jldq);
        assertNotNull(query);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.