private boolean tryRenderingFolded(Resource subject, Value object) { boolean result=false; if(!disableFolding && object instanceof Resource) { Individual individual=graph.findIndividual((Resource)object); if(individual!=null && individual.canBeFoldedBy(subject)) { renderFoldedBlankNode(individual); result=true; } } return result; }
@Override public void handleNamespace(String prefix, String uri) throws RDFHandlerException { graph.addNamespace(prefix, uri); trace("Added prefix '%s' for namespace '%s'.",prefix,uri); }
private void renderSubject(Individual individual) { builder.append(NL).append(utils.toString(individual.getSubject())); if(individual.isAnonymous()) { String tail= !individual.isReferred()? "\t# Not referenced": String.format( "\t# Referenced %d times by resources: %s", individual.getReferences(), renderReferrers(individual.getReferrers())); builder.append(tail); } }
String render() { renderPrefixes(); renderBase(); for(Individual individual:graph) { if(!individual.isReference() && (disableFolding || !individual.isFoldable())) { renderSubject(individual); renderPredicates(false,individual); renderNewLine(); } } return builder.toString(); }
public static String prettyPrint(RepositoryConnection connection, Resource... contexts) throws SesameUtilsException { try { StringWriter writer = new StringWriter(); connection.export(new TurtlePrettyPrinter(writer), contexts); return writer.toString(); } catch(RepositoryException e) { throw new SesameRepositoryFailure(COULD_NOT_SERIALIZE_CONTENTS,e); } catch (RDFHandlerException e) { throw new SesameUtilsAssertionError("Unexpected pretty printer failure",e); } catch(UnsupportedRDFormatException e) { throw new SesameUtilsAssertionError(TURTLE_FORMAT_SHOULD_BE_SUPPORTED, e); } }
void add(Resource subject, URI predicate, Value object) { if(object instanceof Literal) { getOrCreateIndividual(subject).addAssertion(predicate, (Literal)object); } else { IndividualImpl target = getOrCreateIndividual(subject); IndividualImpl linked = getOrCreateIndividual((Resource)object); target.addLink(predicate, linked); } collectNamespace(subject); collectNamespace(predicate); collectNamespace(object); }
void addLink(URI predicate, IndividualImpl individual) { Objects.requireNonNull(predicate,PREDICATE_PARAM); Objects.requireNonNull(individual,INDIVIDUAL_PARAM); findAssertions(predicate).add(individual); individual.addReferrer(subject); }
@Override public int compare(Resource o1, Resource o2) { int result=0; if(o1 instanceof URI) { result=compareURI(o2, (URI)o1); } else { result=compareOther(o1, o2); } return result; }
@Override public String toString() { return getPredicate()+(hasBlankNodes?"* : ":" : ")+getValues(); }
public static <T> void loadSource(RepositoryConnection connection, String base, Source<T> content, URI ctx) throws SesameUtilsException { new ContentLoader(connection, base, ctx).process(content); }
void addAssertion(URI predicate, Literal object) { Objects.requireNonNull(predicate,PREDICATE_PARAM); Objects.requireNonNull(object,OBJECT_PARAM); findAssertions(predicate).add(object); }
private void loadFrom(java.net.URI uri) throws SesameUtilsException { try { loadFrom(URIUtils.toURL(uri)); } catch (MalformedURLException e) { throw new ContentProcessingException("Could not get a proper URL for accessing to the source data",e); } }
private int compareURI(Resource o2, URI uri) { if(o2 instanceof URI) { return TurtleValueUtils.compare(uri,(URI)o2); } else { return -1; } }
@Override public void handleComment(String comment) throws RDFHandlerException { trace("Discarded comment '%s'.",comment); }
@Override public Resource getSubject() { return getSubject(Resource.class); }
int evalAnon(Individual i1) { return i1.isAnonymous()?1:0; }
@Override public String toString() { return stringValue(); }
@Override public URI createURI(String namespace, String localName) { return new CustomURI(this.base,namespace,localName); }