com.github.jsonldjava.core.JsonLdProcessor Java Examples

The following examples show how to use com.github.jsonldjava.core.JsonLdProcessor. 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: JsonldBeanDeserializerModifier.java    From jackson-jsonld with MIT License 6 votes vote down vote up
@Override
public Object deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    Object input = parseJsonldObject(jp);
    if(input == null) {
        return super.deserialize(jp, ctxt);
    }
    try {
        JsonLdOptions options = new JsonLdOptions();
        Object context = contextSupplier.get();
        if(context instanceof JsonNode){
            context = parseJsonldObject(initParser(mapper.treeAsTokens((JsonNode)context)));
        }
        Object obj = JsonLdProcessor.compact(input, context, options);
        JsonParser newParser = initParser(mapper.getFactory().createParser(mapper.valueToTree(obj).toString()));
        return super.deserialize(newParser, ctxt);
    } catch (JsonLdError e) {
        throw new JsonGenerationException("Failed to flatten json-ld", e);
    }
}
 
Example #2
Source File: JSONLDW3CAnnotationMessageConverter.java    From elucidate-server with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected String getStringRepresentation(W3CAnnotation w3cAnnotation, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = w3cAnnotation.getJsonMap();

    JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts);

    Format format = jsonLdProfile.getFormats().get(0);
    if (format.equals(Format.COMPACTED)) {
        jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else if (format.equals(Format.EXPANDED)) {
        List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
        jsonMap = (Map<String, Object>) jsonList.get(0);
    } else if (format.equals(Format.FLATTENED)) {
        jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else {
        throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes());
    }

    jsonMap = reorderJsonAttributes(jsonMap);
    return JsonUtils.toPrettyString(jsonMap);
}
 
Example #3
Source File: JSONLDOAAnnotationHistoryMessageConverter.java    From elucidate-server with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected String getStringRepresentation(OAAnnotationHistory oaAnnotationHistory, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = oaAnnotationHistory.getJsonMap();

    JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts);

    JSONLDProfile.Format format = jsonLdProfile.getFormats().get(0);
    if (format.equals(JSONLDProfile.Format.COMPACTED)) {
        jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else if (format.equals(JSONLDProfile.Format.EXPANDED)) {
        List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
        jsonMap = (Map<String, Object>) jsonList.get(0);
    } else if (format.equals(JSONLDProfile.Format.FLATTENED)) {
        jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else {
        throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes());
    }

    jsonMap = reorderJsonAttributes(jsonMap);
    return JsonUtils.toPrettyString(jsonMap);
}
 
Example #4
Source File: JSONLDW3CBatchOperationMessageConverter.java    From elucidate-server with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected String getStringRepresentation(W3CBatchOperation w3cBatchOperation, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = w3cBatchOperation.getJsonMap();

    JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts);

    Format format = jsonLdProfile.getFormats().get(0);
    if (format.equals(Format.COMPACTED)) {
        jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else if (format.equals(Format.EXPANDED)) {
        List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
        jsonMap = (Map<String, Object>) jsonList.get(0);
    } else if (format.equals(Format.FLATTENED)) {
        jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else {
        throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes());
    }

    jsonMap = reorderJsonAttributes(jsonMap);
    return JsonUtils.toPrettyString(jsonMap);
}
 
Example #5
Source File: JSONLDOAStatisticsPageMessageConverter.java    From elucidate-server with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected String getStringRepresentation(OAStatisticsPage oaStatisticsPage, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = oaStatisticsPage.getJsonMap();

    JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts);

    Format format = jsonLdProfile.getFormats().get(0);
    if (format.equals(Format.COMPACTED)) {
        jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else if (format.equals(Format.EXPANDED)) {
        List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
        jsonMap = (Map<String, Object>) jsonList.get(0);
    } else if (format.equals(Format.FLATTENED)) {
        jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else {
        throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes());
    }

    jsonMap = reorderJsonAttributes(jsonMap);
    return JsonUtils.toPrettyString(jsonMap);
}
 
Example #6
Source File: JSONLDW3CAnnotationPageMessageConverter.java    From elucidate-server with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected String getStringRepresentation(W3CAnnotationPage w3cAnnotationPage, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = w3cAnnotationPage.getJsonMap();

    JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts);

    Format format = jsonLdProfile.getFormats().get(0);
    if (format.equals(Format.COMPACTED)) {
        jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else if (format.equals(Format.EXPANDED)) {
        List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
        jsonMap = (Map<String, Object>) jsonList.get(0);
    } else if (format.equals(Format.FLATTENED)) {
        jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else {
        throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes());
    }

    jsonMap = reorderJsonAttributes(jsonMap);
    return JsonUtils.toPrettyString(jsonMap);
}
 
Example #7
Source File: JSONLDW3CAnnotationCollectionMessageConverter.java    From elucidate-server with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected String getStringRepresentation(W3CAnnotationCollection w3cAnnotationCollection, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = w3cAnnotationCollection.getJsonMap();

    JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts);

    Format format = jsonLdProfile.getFormats().get(0);
    if (format.equals(Format.COMPACTED)) {
        jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else if (format.equals(Format.EXPANDED)) {
        List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
        jsonMap = (Map<String, Object>) jsonList.get(0);
    } else if (format.equals(Format.FLATTENED)) {
        jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else {
        throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes());
    }

    jsonMap = reorderJsonAttributes(jsonMap);
    return JsonUtils.toPrettyString(jsonMap);
}
 
Example #8
Source File: JSONLDOAAnnotationCollectionMessageConverter.java    From elucidate-server with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected String getStringRepresentation(OAAnnotationCollection oaAnnotationCollection, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = oaAnnotationCollection.getJsonMap();

    JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts);

    Format format = jsonLdProfile.getFormats().get(0);
    if (format.equals(Format.COMPACTED)) {
        jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else if (format.equals(Format.EXPANDED)) {
        List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
        jsonMap = (Map<String, Object>) jsonList.get(0);
    } else if (format.equals(Format.FLATTENED)) {
        jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else {
        throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes());
    }

    jsonMap = reorderJsonAttributes(jsonMap);
    return JsonUtils.toPrettyString(jsonMap);
}
 
Example #9
Source File: JSONLDOAAnnotationPageMessageConverter.java    From elucidate-server with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected String getStringRepresentation(OAAnnotationPage oaAnnotationPage, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = oaAnnotationPage.getJsonMap();

    JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts);

    Format format = jsonLdProfile.getFormats().get(0);
    if (format.equals(Format.COMPACTED)) {
        jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else if (format.equals(Format.EXPANDED)) {
        List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
        jsonMap = (Map<String, Object>) jsonList.get(0);
    } else if (format.equals(Format.FLATTENED)) {
        jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else {
        throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes());
    }

    jsonMap = reorderJsonAttributes(jsonMap);
    return JsonUtils.toPrettyString(jsonMap);
}
 
Example #10
Source File: JSONLDW3CStatisticsPageMessageConverter.java    From elucidate-server with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected String getStringRepresentation(W3CStatisticsPage w3cStatisticsPage, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = w3cStatisticsPage.getJsonMap();

    JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts);

    Format format = jsonLdProfile.getFormats().get(0);
    if (format.equals(Format.COMPACTED)) {
        jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else if (format.equals(Format.EXPANDED)) {
        List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
        jsonMap = (Map<String, Object>) jsonList.get(0);
    } else if (format.equals(Format.FLATTENED)) {
        jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else {
        throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes());
    }

    jsonMap = reorderJsonAttributes(jsonMap);
    return JsonUtils.toPrettyString(jsonMap);
}
 
Example #11
Source File: JSONLDOABatchOperationMessageConverter.java    From elucidate-server with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected String getStringRepresentation(OABatchOperation oaBatchOperation, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = oaBatchOperation.getJsonMap();

    JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts);

    Format format = jsonLdProfile.getFormats().get(0);
    if (format.equals(Format.COMPACTED)) {
        jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else if (format.equals(Format.EXPANDED)) {
        List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
        jsonMap = (Map<String, Object>) jsonList.get(0);
    } else if (format.equals(Format.FLATTENED)) {
        jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else {
        throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes());
    }

    jsonMap = reorderJsonAttributes(jsonMap);
    return JsonUtils.toPrettyString(jsonMap);
}
 
Example #12
Source File: JSONLDW3CAnnotationHistoryMessageConverter.java    From elucidate-server with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected String getStringRepresentation(W3CAnnotationHistory w3cAnnotationHistory, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = w3cAnnotationHistory.getJsonMap();

    JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts);

    JSONLDProfile.Format format = jsonLdProfile.getFormats().get(0);
    if (format.equals(JSONLDProfile.Format.COMPACTED)) {
        jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else if (format.equals(JSONLDProfile.Format.EXPANDED)) {
        List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
        jsonMap = (Map<String, Object>) jsonList.get(0);
    } else if (format.equals(JSONLDProfile.Format.FLATTENED)) {
        jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else {
        throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes());
    }

    jsonMap = reorderJsonAttributes(jsonMap);
    return JsonUtils.toPrettyString(jsonMap);
}
 
Example #13
Source File: JSONLDOAAnnotationMessageConverter.java    From elucidate-server with MIT License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected String getStringRepresentation(OAAnnotation oaAnnotation, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = oaAnnotation.getJsonMap();

    JSONLDProfile jsonLdProfile = getJsonLdProfile(contentType, defaultContexts);

    Format format = jsonLdProfile.getFormats().get(0);
    if (format.equals(Format.COMPACTED)) {
        jsonMap = JsonLdProcessor.compact(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else if (format.equals(Format.EXPANDED)) {
        List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
        jsonMap = (Map<String, Object>) jsonList.get(0);
    } else if (format.equals(Format.FLATTENED)) {
        jsonMap = (Map<String, Object>) JsonLdProcessor.flatten(jsonMap, jsonLdProfile.getContexts(), jsonLdOptions);
    } else {
        throw new HttpMediaTypeNotSupportedException(contentType, getSupportedMediaTypes());
    }

    jsonMap = reorderJsonAttributes(jsonMap);
    return JsonUtils.toPrettyString(jsonMap);
}
 
Example #14
Source File: JSONLDW3CAnnotationCollectionMessageConverter.java    From elucidate-server with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected W3CAnnotationCollection getObjectRepresentation(String jsonStr, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = (Map<String, Object>) JsonUtils.fromString(jsonStr);
    List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
    jsonMap = (Map<String, Object>) jsonList.get(0);

    W3CAnnotationCollection w3cAnnotationCollection = new W3CAnnotationCollection();
    w3cAnnotationCollection.setJsonMap(jsonMap);
    return w3cAnnotationCollection;
}
 
Example #15
Source File: JSONLDW3CBatchOperationMessageConverter.java    From elucidate-server with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected W3CBatchOperation getObjectRepresentation(String jsonStr, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = (Map<String, Object>) JsonUtils.fromString(jsonStr);
    List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
    jsonMap = (Map<String, Object>) jsonList.get(0);

    W3CBatchOperation w3cBatchOperation = new W3CBatchOperation();
    w3cBatchOperation.setJsonMap(jsonMap);
    return w3cBatchOperation;
}
 
Example #16
Source File: JSONLDW3CAnnotationHistoryMessageConverter.java    From elucidate-server with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected W3CAnnotationHistory getObjectRepresentation(String jsonStr, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = (Map<String, Object>) JsonUtils.fromString(jsonStr);
    List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
    jsonMap = (Map<String, Object>) jsonList.get(0);

    W3CAnnotationHistory w3cAnnotationHistory = new W3CAnnotationHistory();
    w3cAnnotationHistory.setJsonMap(jsonMap);
    return w3cAnnotationHistory;
}
 
Example #17
Source File: AbstractSchemaValidatorTest.java    From elucidate-server with MIT License 5 votes vote down vote up
protected void validateJson(String jsonFileName) throws IOException, ProcessingException, JsonLdError {

        JsonNode schema = getSchema();
        assertNotNull(schema);

        String jsonStr = getJson(jsonFileName);
        assertNotNull(jsonStr);

        Object jsonObj = JsonUtils.fromString(jsonStr);
        List<Object> expandedJson = JsonLdProcessor.expand(jsonObj);
        jsonStr = JsonUtils.toString(expandedJson);
        JsonNode json = JsonLoader.fromString(jsonStr);

        JsonValidator jsonValidator = JsonSchemaFactory.byDefault().getValidator();
        ProcessingReport processingReport = jsonValidator.validate(schema, json);
        assertNotNull(processingReport);
        if (!processingReport.isSuccess()) {

            ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode();
            assertNotNull(jsonArray);

            Iterator<ProcessingMessage> iterator = processingReport.iterator();
            while (iterator.hasNext()) {
                ProcessingMessage processingMessage = iterator.next();
                jsonArray.add(processingMessage.asJson());
            }

            String errorJson = JsonUtils.toPrettyString(jsonArray);
            assertNotNull(errorJson);

            fail(errorJson);
        }
    }
 
Example #18
Source File: JSONLDW3CAnnotationMessageConverter.java    From elucidate-server with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected W3CAnnotation getObjectRepresentation(String jsonStr, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = (Map<String, Object>) JsonUtils.fromString(jsonStr);
    List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
    jsonMap = (Map<String, Object>) jsonList.get(0);

    W3CAnnotation w3cAnnotation = new W3CAnnotation();
    w3cAnnotation.setJsonMap(jsonMap);
    return w3cAnnotation;
}
 
Example #19
Source File: IOHelper.java    From robot with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Return the current prefixes as a JSON-LD string.
 *
 * @return the current prefixes as a JSON-LD string
 * @throws IOException on any error
 */
public String getContextString() throws IOException {
  try {
    Object compact =
        JsonLdProcessor.compact(
            JsonUtils.fromString("{}"), context.getPrefixes(false), new JsonLdOptions());
    return JsonUtils.toPrettyString(compact);
  } catch (Exception e) {
    throw new IOException(jsonldContextCreationError, e);
  }
}
 
Example #20
Source File: JSONLDInternalTripleCallbackTest.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Test
public void triplesTest() throws JsonLdError, IOException {
	// String inputstring =
	// "{\"@id\":{\"@id\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/machine/DVC-1_8\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceElement\":\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceelement/DET-1_8\",\"http://igreen-projekt.de/ontologies/isoxml#deviceID\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"DVC-1\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceLocalizationLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"FF000000406564\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceProcessData\":[\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/13_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/6_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/14_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/11_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/8_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/4_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/5_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/10_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/2_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/21_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/15_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/16_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/19_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/17_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/3_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/12_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/7_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/18_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/9_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/22_8\",\"http://pc-4107.kl.dfki.de:38080/onlinebox/resource/deviceprocessdata/20_8\"],\"http://igreen-projekt.de/ontologies/isoxml#deviceSerialNumber\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"12345\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceSoftwareVersion\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"01.009\"},\"http://igreen-projekt.de/ontologies/isoxml#deviceStructureLabel\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"31303030303030\"},\"http://igreen-projekt.de/ontologies/isoxml#workingSetMasterNAME\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"A000860020800001\"},\"http://www.w3.org/1999/02/22-rdf-syntax-ns#type\":{\"@iri\":\"http://www.agroxml.de/rdfs#Machine\"},\"http://www.w3.org/2000/01/rdf-schema#label\":{\"@datatype\":\"http://www.w3.org/2001/XMLSchema#string\",\"@literal\":\"Krone
	// Device\"}}";
	final String inputstring = "{ \"@id\":\"http://nonexistent.com/abox#Document1823812\", \"@type\":\"http://nonexistent.com/tbox#Document\" }";
	final String expectedString = "(http://nonexistent.com/abox#Document1823812, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://nonexistent.com/tbox#Document) [null]";
	final Object input = JsonUtils.fromString(inputstring);

	final Model graph = new LinkedHashModel();
	final ParseErrorCollector parseErrorListener = new ParseErrorCollector();
	final ParserConfig parserConfig = new ParserConfig();
	final JSONLDInternalTripleCallback callback = new JSONLDInternalTripleCallback(new StatementCollector(graph),
			SimpleValueFactory.getInstance(), parserConfig, parseErrorListener,
			nodeID -> SimpleValueFactory.getInstance().createBNode(nodeID),
			() -> SimpleValueFactory.getInstance().createBNode());

	JsonLdProcessor.toRDF(input, callback);

	final Iterator<Statement> statements = graph.iterator();

	// contains only one statement (type)
	while (statements.hasNext()) {
		final Statement stmt = statements.next();

		System.out.println(stmt.toString());
		assertEquals("Output was not as expected", stmt.toString(), expectedString);
	}

	assertEquals(0, parseErrorListener.getFatalErrors().size());
	assertEquals(0, parseErrorListener.getErrors().size());
	assertEquals(0, parseErrorListener.getWarnings().size());
}
 
Example #21
Source File: JSONLDOAAnnotationMessageConverter.java    From elucidate-server with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected OAAnnotation getObjectRepresentation(String jsonStr, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = (Map<String, Object>) JsonUtils.fromString(jsonStr);
    List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
    jsonMap = (Map<String, Object>) jsonList.get(0);

    OAAnnotation oaAnnotation = new OAAnnotation();
    oaAnnotation.setJsonMap(jsonMap);
    return oaAnnotation;
}
 
Example #22
Source File: JSONLDOAAnnotationCollectionMessageConverter.java    From elucidate-server with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected OAAnnotationCollection getObjectRepresentation(String jsonStr, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = (Map<String, Object>) JsonUtils.fromString(jsonStr);
    List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
    jsonMap = (Map<String, Object>) jsonList.get(0);

    OAAnnotationCollection oaAnnotationCollection = new OAAnnotationCollection();
    oaAnnotationCollection.setJsonMap(jsonMap);
    return oaAnnotationCollection;
}
 
Example #23
Source File: JSONLDOAAnnotationHistoryMessageConverter.java    From elucidate-server with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected OAAnnotationHistory getObjectRepresentation(String jsonStr, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = (Map<String, Object>) JsonUtils.fromString(jsonStr);
    List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
    jsonMap = (Map<String, Object>) jsonList.get(0);

    OAAnnotationHistory oaAnnotationHistory = new OAAnnotationHistory();
    oaAnnotationHistory.setJsonMap(jsonMap);
    return oaAnnotationHistory;
}
 
Example #24
Source File: JSONLDOABatchOperationMessageConverter.java    From elucidate-server with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
protected OABatchOperation getObjectRepresentation(String jsonStr, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = (Map<String, Object>) JsonUtils.fromString(jsonStr);
    List<Object> jsonList = JsonLdProcessor.expand(jsonMap, jsonLdOptions);
    jsonMap = (Map<String, Object>) jsonList.get(0);

    OABatchOperation oaBatchOperation = new OABatchOperation();
    oaBatchOperation.setJsonMap(jsonMap);
    return oaBatchOperation;
}
 
Example #25
Source File: TurtleW3CAnnotationCollectionMessageConverter.java    From elucidate-server with MIT License 4 votes vote down vote up
@Override
protected String getStringRepresentation(W3CAnnotationCollection w3cAnnotationCollection, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = w3cAnnotationCollection.getJsonMap();
    return JsonLdProcessor.toRDF(jsonMap, turtleTripleCallback, jsonLdOptions).toString();
}
 
Example #26
Source File: JSONLDWriter.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void endRDF() throws RDFHandlerException {
	checkWritingStarted();
	final JSONLDInternalRDFParser serialiser = new JSONLDInternalRDFParser();
	try {
		Object output = JsonLdProcessor.fromRDF(model, serialiser);

		final JSONLDMode mode = getWriterConfig().get(JSONLDSettings.JSONLD_MODE);

		final JsonLdOptions opts = new JsonLdOptions();
		// opts.addBlankNodeIDs =
		// getWriterConfig().get(BasicParserSettings.PRESERVE_BNODE_IDS);
		WriterConfig writerConfig = getWriterConfig();
		opts.setCompactArrays(writerConfig.get(JSONLDSettings.COMPACT_ARRAYS));
		opts.setProduceGeneralizedRdf(writerConfig.get(JSONLDSettings.PRODUCE_GENERALIZED_RDF));
		opts.setUseRdfType(writerConfig.get(JSONLDSettings.USE_RDF_TYPE));
		opts.setUseNativeTypes(writerConfig.get(JSONLDSettings.USE_NATIVE_TYPES));
		// opts.optimize = getWriterConfig().get(JSONLDSettings.OPTIMIZE);

		if (writerConfig.get(JSONLDSettings.HIERARCHICAL_VIEW)) {
			output = JSONLDHierarchicalProcessor.fromJsonLdObject(output);
		}

		if (baseURI != null && writerConfig.get(BasicWriterSettings.BASE_DIRECTIVE)) {
			opts.setBase(baseURI);
		}
		if (mode == JSONLDMode.EXPAND) {
			output = JsonLdProcessor.expand(output, opts);
		}
		// TODO: Implement inframe in JSONLDSettings
		final Object inframe = null;
		if (mode == JSONLDMode.FLATTEN) {
			output = JsonLdProcessor.flatten(output, inframe, opts);
		}
		if (mode == JSONLDMode.COMPACT) {
			final Map<String, Object> ctx = new LinkedHashMap<>();
			addPrefixes(ctx, model.getNamespaces());
			final Map<String, Object> localCtx = new HashMap<>();
			localCtx.put(JsonLdConsts.CONTEXT, ctx);

			output = JsonLdProcessor.compact(output, localCtx, opts);
		}
		if (writerConfig.get(BasicWriterSettings.PRETTY_PRINT)) {
			JsonUtils.writePrettyPrint(writer, output);
		} else {
			JsonUtils.write(writer, output);
		}

	} catch (JsonLdError | IOException e) {
		throw new RDFHandlerException("Could not render JSONLD", e);
	}
}
 
Example #27
Source File: TurtleOAAnnotationMessageConverter.java    From elucidate-server with MIT License 4 votes vote down vote up
@Override
protected String getStringRepresentation(OAAnnotation oaAnnotation, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = oaAnnotation.getJsonMap();
    return JsonLdProcessor.toRDF(jsonMap, turtleTripleCallback, jsonLdOptions).toString();
}
 
Example #28
Source File: TurtleW3CAnnotationHistoryMessageConverter.java    From elucidate-server with MIT License 4 votes vote down vote up
@Override
protected String getStringRepresentation(W3CAnnotationHistory w3CAnnotationHistory, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = w3CAnnotationHistory.getJsonMap();
    return JsonLdProcessor.toRDF(jsonMap, turtleTripleCallback, jsonLdOptions).toString();
}
 
Example #29
Source File: TurtleOABatchOperationMessageConverter.java    From elucidate-server with MIT License 4 votes vote down vote up
@Override
protected String getStringRepresentation(OABatchOperation oaBatchOperation, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = oaBatchOperation.getJsonMap();
    return JsonLdProcessor.toRDF(jsonMap, turtleTripleCallback, jsonLdOptions).toString();
}
 
Example #30
Source File: TurtleW3CStatisticsPageMessageConverter.java    From elucidate-server with MIT License 4 votes vote down vote up
@Override
protected String getStringRepresentation(W3CStatisticsPage w3cStatisticsPage, MediaType contentType) throws Exception {
    Map<String, Object> jsonMap = w3cStatisticsPage.getJsonMap();
    return JsonLdProcessor.toRDF(jsonMap, turtleTripleCallback, jsonLdOptions).toString();
}