当前位置: 首页>>代码示例>>Java>>正文


Java JsonLdError类代码示例

本文整理汇总了Java中com.github.jsonldjava.core.JsonLdError的典型用法代码示例。如果您正苦于以下问题:Java JsonLdError类的具体用法?Java JsonLdError怎么用?Java JsonLdError使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JsonLdError类属于com.github.jsonldjava.core包,在下文中一共展示了JsonLdError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createMetadata

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
/**
 * If a metadata label is configured, read the vertex from the graph into a new BDIO metadata instance.
 */
public BdioMetadata createMetadata() {
    return topology().metadataLabel()
            .flatMap(label -> traversal().V().hasLabel(label).tryNext())
            .map(vertex -> {
                BdioMetadata metadata = new BdioMetadata();
                topology().identifierKey().ifPresent(key -> {
                    metadata.id(vertex.value(key));
                });
                try {
                    Object expandedMetadata = Iterables.getOnlyElement(mapper().expand(ElementHelper.propertyValueMap(vertex)), null);
                    if (expandedMetadata instanceof Map<?, ?>) {
                        ((Map<?, ?>) expandedMetadata).forEach((key, value) -> {
                            if (key instanceof String) {
                                metadata.put((String) key, value);
                            }
                        });
                    }
                } catch (JsonLdError e) {
                    // TODO How should we handle this?
                    e.printStackTrace();
                }
                return metadata;
            })
            .orElse(BdioMetadata.createRandomUUID());
}
 
开发者ID:blackducksoftware,项目名称:bdio,代码行数:29,代码来源:WriteGraphContext.java

示例2: createMetadata

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
/**
 * If a metadata label is configured, store the supplied BDIO metadata on a vertex in the graph.
 */
public void createMetadata(BdioMetadata metadata) {
    topology().metadataLabel().ifPresent(metadataLabel -> {
        GraphTraversalSource g = traversal();

        // Find or create the one vertex with the metadata label
        Vertex vertex = g.V().hasLabel(metadataLabel).tryNext()
                .orElseGet(() -> g.addV(metadataLabel).next());

        // Preserve the identifier (if present and configured)
        if (metadata.id() != null) {
            topology().identifierKey().ifPresent(key -> vertex.property(key, metadata.id()));
        }

        try {
            Map<String, Object> compactMetadata = mapper().compact(metadata);
            ElementHelper.attachProperties(vertex, getNodeProperties(compactMetadata, false));
        } catch (JsonLdError e) {
            // If we wrapped this and re-threw it, it would go back to the document's metadata single which is
            // subscribed to without an error handler, subsequently it would get wrapped in a
            // OnErrorNotImplementedException and passed to `RxJavaPlugins.onError`. So. Just call it directly.
            RxJavaPlugins.onError(e);
        }
    });
}
 
开发者ID:blackducksoftware,项目名称:bdio,代码行数:28,代码来源:ReadGraphContext.java

示例3: cwlJson2Map

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
public Map cwlJson2Map(final String cwljson) {
    Map jsonObject;
    try {
        jsonObject = (Map) JsonUtils.fromString(cwljson);
        // Create a context JSON map containing prefixes and definitions
        Map context = new HashMap();
        // Customise context...
        // Create an instance of JsonLdOptions with the standard JSON-LD options
        JsonLdOptions options = new JsonLdOptions();
        // Customise options...
        // Call whichever JSONLD function you want! (e.g. compact)
        return (Map) JsonLdProcessor.compact(jsonObject, context, options);
    } catch (IOException | JsonLdError e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:common-workflow-language,项目名称:cwlavro,代码行数:17,代码来源:CWL.java

示例4: expandIdentifierAsPropertyOrType

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
/**
 * Use the provided JSON-LD context to expand the given identifier, assuming
 * the identifier is used in a document as a property. Depending on the
 * context, the result may or may not be a valid IRI. If the identifier
 * cannot be expanded by the context, it is returned as-is.
 * 
 * @param identifier
 * @param context
 * @return
 * @throws JsonLdError
 */
public static String expandIdentifierAsPropertyOrType(String identifier,
		Context context) throws JsonLdError {
	// This is very convoluted due to how jsonld-api works
	Map<String, Object> jsonMap = new HashMap<>();
	jsonMap.put(identifier, "ignorethisvalue");
	@SuppressWarnings("unchecked")
	Map<String, Object> result = (Map<String, Object>) (new JsonLdApi()
			.expand(context, jsonMap));
	if (result != null) {
		return result.keySet().iterator().next();
	} else {
		return identifier;
	}

}
 
开发者ID:phenopackets,项目名称:phenopacket-reference-implementation,代码行数:27,代码来源:ContextUtil.java

示例5: toRdf

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
/**
 * Convert a PhenoPacket to RDF triples using the JSON-LD context
 * 
 * @param packet
 * @param base
 *            URI base for generated RDF; if `null` a UUID-based base will
 *            be used
 * @return model containing RDF triples
 * @throws JsonLdError
 * @throws JsonProcessingException
 */
public static Model toRdf(PhenoPacket packet, String base)
		throws JsonLdError, JsonProcessingException {
	PhenoPacket packetWithContext;
	if (packet.getContext() == null) {
		packetWithContext = PhenoPacket.newBuilder(packet)
                           .context(ContextUtil.defaultContextURI)
                           .build();
	} else {
		packetWithContext = packet;
	}
	Model rdfModel = ModelFactory.createDefaultModel();
	StringReader reader = new StringReader(
			JsonGenerator.render(packetWithContext));
	String baseToUse;
	if (base != null) {
		baseToUse = base;
	} else {
		String uuid = UUID.randomUUID().toString();
		baseToUse = "http://phenopackets.org/local/" + uuid + "/";
	}
	RDFDataMgr.read(rdfModel, reader, baseToUse, Lang.JSONLD);
	return rdfModel;
}
 
开发者ID:phenopackets,项目名称:phenopacket-reference-implementation,代码行数:35,代码来源:RdfGenerator.java

示例6: testIdentiferCompaction

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
@Test
public void testIdentiferCompaction() throws IOException, JsonLdError {
	PhenoPacket packet = YamlReader
			.readFile("src/test/resources/context/phenopacket-with-context.yaml");
	Context context = ContextUtil.getJSONLDContext(packet);
	assertThat(ContextUtil.compactIdentifierAsValue(
			"http://myinstitution.example.org/person#1", context),
			equalTo("person#1"));
	String textNotInDocument = "IdentiferNotInDocument";
	assertThat(ContextUtil.compactIdentifierAsValue(textNotInDocument,
			context), equalTo(textNotInDocument));
	assertThat(ContextUtil.compactIdentifierAsValue("rdfs:label", context),
			equalTo("rdfs:label"));
	assertThat(ContextUtil.compactIdentifierAsPropertyOrType(
			"http://myinstitution.example.org/person#1", context),
			not("person#1"));
}
 
开发者ID:phenopackets,项目名称:phenopacket-reference-implementation,代码行数:18,代码来源:ContextTest.java

示例7: testReadRdf

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
@Test
public void testReadRdf() throws IOException, JsonLdError {
	// FIXME this does not really test the output
	PhenoPacket packet = YamlReader
			.readFile("src/test/resources/context/phenopacket-with-context.yaml");
	Model model = RdfGenerator.toRdf(packet, null);
	String packetID = packet.getId();
	PhenoPacket newPacket = RdfReader.readModel(model,
			ContextUtil.expandIdentifierAsValue(packetID, packet));
	ObjectMapper m = new ObjectMapper();
	m.setSerializationInclusion(JsonInclude.Include.NON_NULL);
	m.setFilterProvider(new SimpleFilterProvider().addFilter(
			"PhenoPacketClass", SimpleBeanPropertyFilter.serializeAll()));
	ObjectWriter writer = m.writerWithDefaultPrettyPrinter();
	System.out.println(writer.writeValueAsString(newPacket));
}
 
开发者ID:phenopackets,项目名称:phenopacket-reference-implementation,代码行数:17,代码来源:RdfTest.java

示例8: documentation

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
@GET
@Path("/doc")
@Produces({MediaType.APPLICATION_LD_JSON, MediaType.APPLICATION_JSON})
public void documentation(@Suspended final AsyncResponse response)
    throws JsonLdError, IOException {
  String rootURL = URIUtils.extractRootURL(uriInfo.getRequestUri());
  Model apiDoc = contextProvider.getRDFModel(API_DOCUMENTATION, MapBuilder.newMap()
      .put(ContextProvider.VAR_ROOT_URL, rootURL)
      .put(ContextProvider.VAR_WAMP_URL, rootURL + config.wampPublicPath())
      .build());
  Map<String, Object> frame = contextProvider.getFrame(API_DOCUMENTATION, rootURL);

  Observable<List<Resource>> prototypes = query.select(QUERY_SYSTEM_PROTOTYPES)
      .map((ResultSet rs) ->
          defineResourceIndividual(apiDoc, rootURL, LINK_SYSTEMS, rs, SSN.System));

  Observable<Model> supportedProperties = addSupportedProperties(apiDoc, rootURL, prototypes);

  supportedProperties.map((__) -> {
    try {
      return JsonUtils.toString(ModelJsonLdUtils.toJsonLdCompact(apiDoc, frame));
    } catch (Throwable e) {
      throw Exceptions.propagate(e);
    }
  }).subscribe(resume(response));
}
 
开发者ID:semiotproject,项目名称:semiot-platform,代码行数:27,代码来源:RootResource.java

示例9: triplesTest

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
@Test
public void triplesTest() throws IOException, JsonLdError {
    final InputStream in = getClass().getClassLoader().getResourceAsStream(
            "testfiles/product.jsonld");
    final Object input = JsonUtils.fromInputStream(in);

    final ClerezzaTripleCallback callback = new ClerezzaTripleCallback();

    final MGraph graph = (MGraph) JsonLdProcessor.toRDF(input, callback);

    for (final Triple t : graph) {
        System.out.println(t);
    }
    assertEquals("Graph size", 13, graph.size());

}
 
开发者ID:jsonld-java,项目名称:jsonld-java-clerezza,代码行数:17,代码来源:ClerezzaTripleCallbackTest.java

示例10: curiesInContextTest

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
@Test
public void curiesInContextTest() throws IOException, JsonLdError {
    final InputStream in = getClass().getClassLoader().getResourceAsStream(
            "testfiles/curies-in-context.jsonld");
    final Object input = JsonUtils.fromInputStream(in);

    final ClerezzaTripleCallback callback = new ClerezzaTripleCallback();

    final MGraph graph = (MGraph) JsonLdProcessor.toRDF(input, callback);

    for (final Triple t : graph) {
        System.out.println(t);
        assertTrue("Predicate got fully expanded", t.getPredicate().getUnicodeString()
                .startsWith("http"));
    }
    assertEquals("Graph size", 3, graph.size());

}
 
开发者ID:jsonld-java,项目名称:jsonld-java-clerezza,代码行数:19,代码来源:ClerezzaTripleCallbackTest.java

示例11: deserialize

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:io-informatics,项目名称:jackson-jsonld,代码行数:20,代码来源:JsonldBeanDeserializerModifier.java

示例12: validateAndStore

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
public WebAnnotation validateAndStore(WebAnnotationPrototype prototype) {
  try {
    String json = new ObjectMapper().writeValueAsString(prototype);
    Map<String, Object> jsonObject = (Map<String, Object>) JsonUtils.fromString(json);

    String resourceRef = extractResourceRef(jsonObject);
    AntiochResource antiochResource = extractAntiochResource(resourceRef);
    AntiochAnnotation annotation = createWebAnnotation(json, antiochResource);

    jsonObject.put("@id", webAnnotationURI(annotation.getId()));
    String json2 = new ObjectMapper().writeValueAsString(jsonObject);
    return new WebAnnotation(annotation.getId())//
            .setJson(json2)//
            .setETag(String.valueOf(prototype.getModified().hashCode()));

  } catch (IOException | JsonLdError e) {
    throw new BadRequestException(e.getMessage());
  }
}
 
开发者ID:HuygensING,项目名称:antioch,代码行数:20,代码来源:WebAnnotationService.java

示例13: parse

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
@Override
public RDFDataset parse(Object input) throws JsonLdError {
    final RDFDataset result = new RDFDataset();
    if (input instanceof Statement) {
        handleStatement(result, (Statement) input);
    } else if (input instanceof Model) {
        final Set<Namespace> namespaces = ((Model) input).getNamespaces();
        for (final Namespace nextNs : namespaces) {
            result.setNamespace(nextNs.getName(), nextNs.getPrefix());
        }

        for (final Statement nextStatement : (Model) input) {
            handleStatement(result, nextStatement);
        }
    }
    return result;
}
 
开发者ID:jsonld-java,项目名称:jsonld-java-tools,代码行数:18,代码来源:RDF4JJSONLDRDFParser.java

示例14: parse

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
@Override
public RDFDataset parse(Object input) throws JsonLdError {
    final RDFDataset result = new RDFDataset();

    // empty dataset if no input given
    if (input == null) {
        return result;
    }

    if (input instanceof ModelSet) {
        importModelSet(result, (ModelSet) input);
    } else if (input instanceof Model) {
        importModel(result, (Model) input);
    } else {
        throw new JsonLdError(Error.INVALID_INPUT,
                "RDF2Go parser expects a Model or ModelSet object as input");
    }

    return result;
}
 
开发者ID:jsonld-java,项目名称:jsonld-java-rdf2go,代码行数:21,代码来源:RDF2GoRDFParser.java

示例15: testToRDF

import com.github.jsonldjava.core.JsonLdError; //导入依赖的package包/类
@Test
public void testToRDF() throws JsonLdError, IOException {
    final String inputstring = "{ `@id`:`http://nonexistent.com/abox#Document1823812`, `@type`:`http://nonexistent.com/tbox#Document` }"
            .replace('`', '"');
    final String expectedString = "null - http://nonexistent.com/abox#Document1823812 - http://www.w3.org/1999/02/22-rdf-syntax-ns#type - http://nonexistent.com/tbox#Document";
    final Object input = JsonUtils.fromString(inputstring);

    final RDF2GoTripleCallback callback = new RDF2GoTripleCallback();

    final ModelSet model = (ModelSet) JsonLdProcessor.toRDF(input, callback);

    // contains only one statement (type)
    final ClosableIterator<Statement> statements = model.iterator();
    final Statement stmt = statements.next();
    assertEquals(expectedString, stmt.getContext() + " - " + stmt.toString());
    assertFalse("Deserialized RDF contains more triples than expected", statements.hasNext());
}
 
开发者ID:jsonld-java,项目名称:jsonld-java-rdf2go,代码行数:18,代码来源:RDF2GoTripleCallbackTest.java


注:本文中的com.github.jsonldjava.core.JsonLdError类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。