Package org.apache.stanbol.commons.jsonld

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


    public void testToQueryFromJsonLd2() throws Exception {
        JsonLd jldq = new JsonLd();
        jldq.addNamespacePrefix("http://iks-project.eu/ont/", "iks");
        jldq.addNamespacePrefix("http://upd.de/persons/", "upb");
       
        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("person", new JsonLdIRI("upb:fchrist"));

        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


        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.IRI);
                        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

TOP

Related Classes of org.apache.stanbol.commons.jsonld.JsonLdResource

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.