@Override public int compareTo(Node o) { if(o==null) { return 1; } if(o==this) { return 0; } if(o instanceof BlankNode|| o instanceof Literal) { return -1; } return getIdentity().toString().compareTo(((URIRef)o).getIdentity().toString()); }
public URIRef newURIRef(URI identity) { return new URIRef(identity); }
@Override public boolean accept(Triple t) { return predicate==null || t.getPredicate().equals(predicate); } }
@Override public int compareTo(Triple o) { if(this==o) { return 0; } if(o==null) { return 1; } int result=getSubject().compareTo(o.getSubject()); if(result!=0) { return result; } result=getPredicate().compareTo(o.getPredicate()); if(result!=0) { return result; } return getObject().compareTo(o.getObject()); }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("<").append(getIdentity()).append(">"); return builder.toString(); }
private void collectNamespace(Node element) { if(element instanceof URIRef) { URIRef uriRef = (URIRef)element; if(uriRef.getIdentity().isAbsolute() && !uriRef.getIdentity().isOpaque()) { String namespace = ModelUtils.getNamespace(uriRef); if(LOGGER.isTraceEnabled() && !usedNamespaces.contains(namespace)) { LOGGER.trace(String.format("Collected namespace: %s",namespace)); } usedNamespaces.add(namespace); } } }
static String getNamespace(URIRef uri) { String uriString = uri.getIdentity().toString(); int localNameIdx = getLocalNameIndex(uriString); return uriString.substring(0, localNameIdx); }
@Override public org.openrdf.model.Resource visitURIRef( URIRef node, org.openrdf.model.Resource defaultResult) { return valueFactory.createURI(baseURI.resolve(node.getIdentity()).toString()); }
static String getLocalName(URIRef uri) { String uriString = uri.getIdentity().toString(); int localNameIdx = getLocalNameIndex(uriString); return uriString.substring(localNameIdx); }
@Override public org.openrdf.model.Value visitURIRef(URIRef node, org.openrdf.model.Value defaultResult) { return valueFactory.createURI(baseURI.resolve(node.getIdentity()).toString()); }
private org.openrdf.model.URI formatPredicate(URIRef predicate) { return valueFactory.createURI(baseURI.resolve(predicate.getIdentity()).toString()); }
@Override public ResourceResolution visitURIRef(URIRef endpointURIRef, ResourceResolution defaultResult) { URIRef alternativeURIRef=(URIRef)alternativeNode; URI uri = resolver.resolve(endpointURIRef.getIdentity(), alternativeURIRef.getIdentity()); URIDescriptor descriptor = describer.describe(uri); return ResourceResolutionFactory.customResolution(uri, descriptor); }
static Namespace fromURI(URIRef uri) { for(Namespace namespace:values()) { if(uri.getIdentity().toString().startsWith(namespace.getId())) { return namespace; } } return UNKNOWN; }
@Override public String visitURIRef(URIRef node, String defaultResult) { return node.getIdentity().toString(); } };
private Individual<?, ?> resolveURIRef(URIRef node) { if(this.resolution.isTransient()) { return this.dataSet.individual(this.resolution.realURI(),NewIndividual.class); } URI location = node.getIdentity(); for(URI identity:URIHelper.getParents(location)) { ManagedIndividualId resourceId = this.resourceResolver.resolveLocation(identity); if(resourceId!=null) { if(identity.equals(location)) { return this.dataSet.individual(resourceId, ManagedIndividual.class); } else { URI relativePath = identity.relativize(location); RelativeIndividualId relativeId = RelativeIndividualId.createId(resourceId, relativePath); return this.dataSet.individual(relativeId,RelativeIndividual.class); } } } return this.dataSet.individual(location,ExternalIndividual.class); }
DataSet unmarshall(Context context, ResourceResolver resourceResolver, String content) throws ContentTransformationException { checkNotNull(content,"Content cannot be null"); Iterable<Triple> triples= this.provider. unmarshallContent(context,content,this.targetMediaType); DataSet dataSet= DataSets. createDataSet( NamingScheme.getDefault().name(context.getBase())); ValueAdapter adapter=new ValueAdapter(resourceResolver,dataSet); ResourceResolution nullResolution= ResourceResolutionFactory.nullResolution(); for(Triple triple:triples) { Individual<?,?> individual= adapter. getIndividual(triple.getSubject(),nullResolution); individual. addValue( triple.getPredicate().getIdentity(), adapter.getValue(triple.getObject(),nullResolution)); } return dataSet; }
private DataSet surrogateUnmarshall(String entity, URI endpoint) throws ContentTransformationException { TripleResolver tripleResolver= TripleResolver. builder(). withApplication(this.applicationBase). withEndpoint(endpoint). withAlternative(createAlternative(endpoint)). withEntity(entity, this.mediaType). build(); DataSet dataSet=DataSets.createDataSet(NamingScheme.getDefault().name(endpoint)); ValueAdapter adapter=new ValueAdapter(resourceResolver,dataSet); for(TripleResolution tripleResolution:tripleResolver.tripleResolutions()) { Triple triple=tripleResolution.triple(); Individual<?,?> individual=adapter.getIndividual(triple.getSubject(),tripleResolution.subjectResolution()); individual. addValue( triple.getPredicate().getIdentity(), adapter.getValue(triple.getObject(),tripleResolution.objectResolution())); } return dataSet; }