private Map<URI, Record> extractRelated(final Record record) throws Throwable { // TODO: this has to be done better using some Schema object final URI id = record.getID(); final URI type = record.getSystemType(); final Map<URI, Record> map = Maps.newHashMap(); if (type.equals(KS.RESOURCE)) { for (final URI mentionID : record.get(KS.HAS_MENTION, URI.class)) { map.put(mentionID, Record.create(mentionID, KS.MENTION).add(KS.MENTION_OF, id)); } } else if (type.equals(KS.MENTION)) { final URI resourceID = record.getUnique(KS.MENTION_OF, URI.class); if (resourceID != null) { map.put(resourceID, Record.create(resourceID, KS.RESOURCE).add(KS.HAS_MENTION, id)); } } else { // TODO: handle entities, axioms and contexts throw new Error("Unexpected type: " + type); } return map; }
private Object encodeRecord(final Record record, @Nullable final Set<URI> propertiesToEncode) { final URI id = record.getID(); final Object encodedID = id == null ? null : encodeIdentifier(id); final List<Object> props = Lists.newArrayList(); for (final URI property : record.getProperties()) { if (propertiesToEncode == null || propertiesToEncode.contains(property)) { ensureInDictionary(property); final List<? extends Object> nodes = record.get(property); if (property.equals(RDF.TYPE)) { for (final Object value : nodes) { if (value instanceof URI) { ensureInDictionary((URI) value); } } } final GenericData.Record prop = new GenericData.Record(Schemas.PROPERTY); prop.put("propertyURI", encodeIdentifier(property)); prop.put("propertyValue", encodeNodes(nodes)); props.add(prop); } } return SerializerAvro.newGenericRecord(Schemas.RECORD, encodedID, props); }
if (oldRel != null && newRel != null) { for (final URI property : oldRel.getProperties()) { final List<URI> newValues = newRel.get(property, URI.class); if (!newValues.isEmpty()) { final List<URI> oldValues = oldRel.get(property, URI.class); oldRel.remove(property, newValues); newRel.remove(property, oldValues); assert oldRel != null; if (!property.equals(RDF.TYPE)) { related.remove(property, oldRel.get(property)); assert newRel != null; if (!property.equals(RDF.TYPE)) { related.add(property, newRel.get(property));
representation.getMetadata().setID(metadata.getID()); for (final URI property : metadata.getProperties()) { representation.getMetadata().set(property, metadata.get(property));