@Override public void process(final Triple triple) { assert !isClosed(); if (triple.getObjectType() != ObjectType.STRING) { return; } final String objectValue = retrieveObjectValue(triple.getObject()); getReceiver().process(new Triple(triple.getSubject(), triple.getPredicate(), objectValue)); }
@Override public int compare(final Triple o1, final Triple o2) { return order.order(o1.compareTo(o2)); } };
public Triple(final String subject, final String predicate, final String object, final ObjectType objectType) { this.subject = subject; this.predicate = predicate; this.object = object; this.objectType = objectType; preCompHashCode = computeHashCode(); }
private Path buildFilePath(final Triple triple) { final Path file = Paths.get(triple.getSubject(), triple.getPredicate()); return baseDir.resolve(file).toAbsolutePath().normalize(); }
public void decodeTriple(final Triple triple) { if(triple.getObjectType() == ObjectType.STRING){ getReceiver().literal(triple.getPredicate(), triple.getObject()); }else if (triple.getObjectType() == ObjectType.ENTITY){ emitter.setDefaultName(triple.getPredicate()); parser.parse(triple.getObject()); }else{ throw new UnsupportedOperationException(triple.getObjectType() + " can not yet be decoded"); } }
public static Triple read(final ObjectInputStream in) throws IOException { try { return new Triple(in.readUTF(), in.readUTF(), in.readUTF(), (ObjectType) in.readObject()); } catch (final ClassNotFoundException e) { throw new IOException("Cannot read triple", e); } }
@Override public void process(final Triple obj) { subjectMatcher.reset(obj.getSubject()); predicateMatcher.reset(obj.getPredicate()); objectMatcher.reset(obj.getObject()); final boolean matches = subjectMatcher.matches() || predicateMatcher.matches() || objectMatcher.matches(); if ((matches && passMatches) || (!matches && !passMatches)) { getReceiver().process(obj); } }
@Override public final void process(final Triple triple) { if (triple.getSubject().indexOf('&') == -1) { if (!inHeader) { throw new IllegalArgumentException( "Marginal counts and joint count must not be mixed. Marginal counts must appear first, joint counts second"); } if (!triple.getSubject().startsWith(MARGINAL_PREFIX)) { throw new IllegalArgumentException("Marginal counts must start with '1:'"); } final int marginal = Integer.parseInt(triple.getObject()); if (marginal >= minCount) { marginals.put(triple.getSubject().substring(2), Integer.valueOf(marginal)); } } else { inHeader = false; if (!triple.getSubject().startsWith(JOINT_PREFIX)) { throw new IllegalArgumentException("Joint counts must start with '2:'"); } final int nab = Integer.parseInt(triple.getObject()); final String[] keyParts = KEY_SPLIT_PATTERN.split(triple.getSubject().substring(2)); if (nab >= minCount) { final int na = getMarginal(keyParts[0]); final int nb = getMarginal(keyParts[1]); processCount(keyParts[0], keyParts[1], na, nb, nab); } } }
@Override public int compare(final Triple o1, final Triple o2) { return order.order(o1.getSubject().compareTo(o2.getSubject())); } };
@Override public int compare(final Triple o1, final Triple o2) { return order.order(o1.getPredicate().compareTo(o2.getPredicate())); } };
private void dispatch(final String name, final String value, final ObjectType type) { if (redirect) { if (StandardEventNames.ID.equals(name)) { currentId = value; } else { final Matcher matcher = REDIRECT_PATTERN.matcher(name); if (matcher.find()) { getReceiver().process(new Triple(matcher.group(1), matcher.group(2), value, type)); } else { nameBuffer.add(name); valueBuffer.add(value); typeBuffer.add(type); } } } else { getReceiver().process(new Triple(currentId, name, value, type)); } }
@Override public void process(final T obj) { if(obj instanceof Triple){ final Triple triple = (Triple)obj; vars.put("s", triple.getSubject()); vars.put("p", triple.getPredicate()); vars.put("o", triple.getObject()); getReceiver().process(StringUtil.format(template, vars)); }else{ final Matcher matcher = OBJ_PATTERN.matcher(template); getReceiver().process(matcher.replaceAll(obj.toString())); } } }
@Override public void process(final Triple triple) { if (currentSubject == null) { currentSubject = triple.getSubject(); getReceiver().startRecord(currentSubject); } if (currentSubject.equals(triple.getSubject())) { decodeTriple(triple); } else { getReceiver().endRecord(); currentSubject = triple.getSubject(); getReceiver().startRecord(currentSubject); decodeTriple(triple); } }
@Override public void process(final Triple triple) { final Path filePath = buildFilePath(triple); ensureParentPathExists(filePath); try(final Writer writer = Files.newBufferedWriter(filePath, encoding)) { writer.write(triple.getObject()); } catch (final IOException e) { throw new MetafactureException(e); } }
@Override public void process(final Triple triple) { getReceiver().startRecord(triple.getSubject()); if(triple.getObjectType() == ObjectType.STRING){ getReceiver().literal(triple.getPredicate(), triple.getObject()); }else if (triple.getObjectType() == ObjectType.ENTITY){ emitter.setDefaultName(triple.getPredicate()); parser.parse(triple.getObject()); }else{ throw new UnsupportedOperationException(triple.getObjectType() + " can not yet be decoded"); } getReceiver().endRecord(); }
@Override public void endRecord() { assert !isClosed(); nestingLevel = 0; if (nestingLevel == encodeLevel) { endEncode(); } if (redirect) { for (int i = 0; i < nameBuffer.size(); ++i) { getReceiver().process(new Triple(currentId, nameBuffer.get(i), valueBuffer.get(i), typeBuffer.get(i))); } nameBuffer.clear(); valueBuffer.clear(); typeBuffer.clear(); } }
@Override public void process(final Triple triple) { final String[] elements = { triple.getSubject(), triple.getPredicate(), triple.getObject(), }; getReceiver().process(new Triple( elements[subjectFrom.ordinal()], elements[predicateFrom.ordinal()], elements[objectFrom.ordinal()] )); }
@Override protected void processCount(final String varA, final String varB, final int countA, final int countB, final int countAandB) { for (Metric metric : metrics) { final double value = metric.calculate(countA, countB, countAandB, getTotal()); getReceiver().process(new Triple(varA + "&" + varB, metric.toString(), String.valueOf(value))); } } }
private void writeResult() { final Compare compareBy = getCompare(); switch (compareBy) { case ALL: getReceiver().process(new Triple(current.toString(), countPredicate , String.valueOf(count))); break; case OBJECT: getReceiver().process(new Triple(current.getObject(), countPredicate, String.valueOf(count))); break; case PREDICATE: getReceiver().process(new Triple(current.getPredicate(), countPredicate, String.valueOf(count))); break; case SUBJECT: default: getReceiver().process(new Triple(current.getSubject(), countPredicate, String.valueOf(count))); break; } }