public void writeTo(final String location) throws IOException { try (Writer writer = IO.utf8Writer(IO.buffer(IO.write(location)))) { writeTo(writer); } }
static RDFProcessor create(final String name, final String... args) { final Options options = Options.parse("!", args); final String namespace = options.getPositionalArg(0, String.class); return new ProcessorASNorm(namespace); }
public static KAFDocument readDocument(@Nullable final Path path) throws IOException { final KAFDocument document; if (path == null) { document = KAFDocument.createFromStream(IO.utf8Reader(IO.buffer(System.in))); document.getPublic().publicId = ""; } else { try (BufferedReader reader = Files.newBufferedReader(path)) { document = KAFDocument.createFromStream(reader); document.getPublic().publicId = path.toString(); } } return document; }
private String format(final Value value) { if (value instanceof URI) { final URI uri = (URI) value; final String ns = uri.getNamespace(); final String prefix = this.namespaces.prefixFor(ns); if (prefix == null) { return escape("<.." + ns.charAt(ns.length() - 1) + uri.getLocalName() + ">"); } else { return prefix + ":" + escape(uri.getLocalName()); } } return escape(Statements.formatValue(value, this.namespaces)); }
public static String format(final Value value) { // Emit literal without lang / datatype for easier consumption in analysis tools if (value instanceof Value) { // was instanceof Resource return Statements.formatValue(value, null); } else if (value != null) { return value.stringValue(); } else { return ""; } }
public static synchronized SubjectivityLexicon getInstance() { if (instance == null) { final String location = Objects.firstNonNull( Environment.getProperty("subjectivity.lexicon.home"), "SubjectivityLexicon.tsv"); try { instance = Lexicon.readFrom(SubjectivityLexicon.class, Lexeme.class, location); } catch (final Throwable ex) { throw new Error("Could not read default subjectivity lexicon at " + location, ex); } } return instance; }
private CountQuery(final String name, final Properties properties, @Nullable final Template condition) { super(name, properties, condition.getVariables(), ImmutableList.of("size")); this.layer = (URI) Statements.parseValue(properties.getProperty("layer")); this.condition = condition; }
@Nullable private static String shorten(@Nullable final URI uri) { if (uri == null) { return null; } final String prefix = Namespaces.DEFAULT.prefixFor(uri.getNamespace()); if (prefix != null) { return prefix + ':' + uri.getLocalName(); } return "<../" + uri.getLocalName() + ">"; }
private URI emitRelationMention(final Iterable<Term> extent, final URI type) { final List<Term> terms = Ordering.from(Term.OFFSET_COMPARATOR).sortedCopy(extent); final URI mentionURI = emitNIF(terms); this.model.add(mentionURI, KS.MENTION_OF, this.documentURI); this.model.add(mentionURI, RDF.TYPE, type); return mentionURI; }
public static String format(final TupleExpr expr) { return expr == null ? "null" : new SPARQLRenderer(Namespaces.DEFAULT.prefixMap(), false) .renderTupleExpr(expr).replaceAll("[\n\r\t ]+", " "); }
private static void emit(final RDFHandler handler, final Resource subj, final URI pred, final Object obj, final Resource ctx) throws RDFHandlerException { final Value o = Statements.convert(obj, Value.class); if (subj != null && pred != null && o != null) { if (ctx == null) { handler.handleStatement(Statements.VALUE_FACTORY.createStatement(subj, pred, o)); } else { handler.handleStatement(Statements.VALUE_FACTORY.createStatement(subj, pred, o, ctx)); } } }
private static String valueToHash(final Value v) { final StringBuilder sb = new StringBuilder(); if (v instanceof URI) { sb.append('u'); sb.append('#'); sb.append(v.stringValue()); } else if (v instanceof BNode) { sb.append('b'); sb.append('#'); sb.append(v.stringValue()); } else if (v instanceof Literal) { sb.append('l'); sb.append('#'); sb.append(Hash.murmur3(v.stringValue()).toString()); } return Hash.murmur3(sb.toString()).toString(); }
@Override public String toString() { final StringBuilder builder = new StringBuilder(); builder.append("STATIC TERMS (").append(this.staticTerms.size()).append("):"); for (final URI staticTerm : this.staticTerms) { builder.append("\n").append(Statements.formatValue(staticTerm, Namespaces.DEFAULT)); } builder.append("\n\nRULES (").append(this.rules.size()).append("):"); for (final Rule rule : this.rules) { builder.append("\n").append(rule); } return builder.toString(); }
public static synchronized Intensities getInstance() { if (instance == null) { final String location = Objects.firstNonNull( Environment.getProperty("intensities.home"), "intensities.tsv"); try { instance = Lexicon.readFrom(Intensities.class, Lexeme.class, location); } catch (final Throwable ex) { throw new Error("Could not read default intensity lexicon at " + location, ex); } } return instance; }
@Nullable private String shorten(@Nullable final URI uri) { if (uri == null) { return null; } final String prefix = this.namespaces.prefixFor(uri.getNamespace()); if (prefix != null) { return prefix + ':' + uri.getLocalName(); } return "<../" + uri.getLocalName() + ">"; }
private void emitMeta(@Nullable final URI subject, @Nullable final URI property, @Nullable final Object objects) { if (subject != null && property != null) { for (final Value object : extract(Value.class, objects, RDF.TYPE.equals(property) ? RDFGenerator.this.typeMap : null)) { this.statements.add(FACTORY.createStatement(subject, property, object)); } } }
public static synchronized SenticNet getInstance() { if (instance == null) { final String location = Objects.firstNonNull( Environment.getProperty("senticnet.home"), "SenticNet.tsv"); try { instance = Lexicon.readFrom(SenticNet.class, Lexeme.class, location); } catch (final Throwable ex) { throw new Error("Could not read default subjectivity lexicon at " + location, ex); } } return instance; }
@Nullable private static String shorten(@Nullable final URI uri) { if (uri == null) { return null; } final String prefix = Namespaces.DEFAULT.prefixFor(uri.getNamespace()); if (prefix != null) { return prefix + ':' + uri.getLocalName(); } return "<../" + uri.getLocalName() + ">"; }