Search in sources :

Example 1 with Triple

use of nl.knaw.huygens.timbuctoo.rdf.Triple in project timbuctoo by HuygensING.

the class TriplePropertyConverter method to.

@Override
public Tuple<String, List<Triple>> to(HyperLinksProperty property) throws IOException {
    String blankNode = "_:" + UUID.randomUUID();
    String propertyName = property.getName();
    String pred = createMetadata(propertyName);
    List<Triple> triples = Lists.newArrayList(new LinkTriple(subjectUri, pred, blankNode));
    JsonNode jsonNode = objectMapper.readTree(property.getValue());
    for (Iterator<JsonNode> elements = jsonNode.elements(); elements.hasNext(); ) {
        JsonNode jn = elements.next();
        jn.fieldNames().forEachRemaining(field -> {
            String predicate = pred + field;
            String fieldValue = jn.get(field).asText();
            String object = StringUtils.isBlank(fieldValue) ? "\"\"" : fieldValue;
            triples.add(new LinkTriple(blankNode, predicate, object));
        });
    }
    return tuple(propertyName, triples);
}
Also used : Triple(nl.knaw.huygens.timbuctoo.rdf.Triple) LiteralTriple(nl.knaw.huygens.timbuctoo.rdf.LiteralTriple) LinkTriple(nl.knaw.huygens.timbuctoo.rdf.LinkTriple) LinkTriple(nl.knaw.huygens.timbuctoo.rdf.LinkTriple) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)1 LinkTriple (nl.knaw.huygens.timbuctoo.rdf.LinkTriple)1 LiteralTriple (nl.knaw.huygens.timbuctoo.rdf.LiteralTriple)1 Triple (nl.knaw.huygens.timbuctoo.rdf.Triple)1