コード例 #1
0
  private Optional<Value> processGDMObject(final Node object) {

    final NodeType objectType = object.getType();

    switch (objectType) {
      case Literal:
        final LiteralNode literalNode = (LiteralNode) object;
        final String value = literalNode.getValue();

        final String finalValue;

        if (!value.trim().isEmpty()) {

          // note: we need to trim the values; otherwise, we'll get a
          // 'wikibase-validator-malformed-value' error
          final String trimmedValue = value.trim();

          // note: we need to cut the values, if they are longer then 400 characters; otherwise,
          // we'll get a 'wikibase-validator-too-long' error
          finalValue = cutLongValue(trimmedValue);
        } else {

          // empty values are not possible in Wikidata - insert placeholder for now

          // finalValue = VALUE_WAS_EMPTY_ORIGINALLY;

          return Optional.empty();
        }

        return Optional.ofNullable(Datamodel.makeStringValue(finalValue));
      case Resource:

        // create ItemIdValue, i.e., create a Wikidata Item just with the Id as label

        final ResourceNode resourceNode = (ResourceNode) object;

        return Optional.ofNullable(processGDMResourceNode(resourceNode));
      default:

        // TODO throw an exception or just skip and log (i.e. these should be bnodes)
    }

    return Optional.empty();
  }
コード例 #2
0
  private static String printGDMNode(final Node node) {

    final StringBuilder sb = new StringBuilder();

    final Long id = node.getId();

    sb.append("id = '");

    if (id != null) {

      sb.append(id);
    } else {

      sb.append("no node id available");
    }

    final NodeType nodeType = node.getType();

    switch (nodeType) {
      case Literal:
        sb.append("' :: ");

        final LiteralNode literalNode = (LiteralNode) node;
        final String value = literalNode.getValue();

        sb.append("value = '").append(value);

        break;
      case Resource:
        sb.append("' :: ");

        final ResourceNode resourceNode = (ResourceNode) node;
        final String resourceURI = resourceNode.getUri();

        sb.append("uri = '").append(resourceURI);

        break;
    }

    sb.append("' :: type = '").append(nodeType).append("'}");

    return sb.toString();
  }