示例#1
0
  public void addHash(Quad quad) throws IOException {
    // TODO 1. we should ignore blank nodes
    // TODO 2. we should ignore certain triples

    String subjectHash = "";
    if (!(quad.getSubject().isBlank())) {
      subjectHash = quad.getSubject().toString();
    }

    String propertyHash = quad.getPredicate().toString();

    String objectHash = "";
    if (!(quad.getObject().isBlank())) {
      objectHash = quad.getObject().toString();
    }

    String graphHash = "";
    if (quad.getGraph() != null) {
      graphHash = quad.getGraph().toString();
    }

    this.hashSet.add(this.fastHashing(subjectHash + propertyHash + objectHash + graphHash));

    //	this.hashSet.add(DigestUtils.md5Hex(subjectHash+propertyHash+objectHash+graphHash));
  }
  @Override
  public void send(Quad quad) {
    try {
      byte[] s = tdbloader3.serialize(quad.getSubject()).getBytes("UTF-8");
      byte[] p = tdbloader3.serialize(quad.getPredicate()).getBytes("UTF-8");
      byte[] o = tdbloader3.serialize(quad.getObject()).getBytes("UTF-8");
      byte[] g = null;
      // Union graph?!
      if (!quad.isTriple() && !quad.isDefaultGraph())
        g = tdbloader3.serialize(quad.getGraph()).getBytes("UTF-8");

      digest.reset();
      digest.update(s); // TODO: should we do something better here?
      digest.update(p);
      digest.update(o);
      if (g != null) digest.update(g.toString().getBytes("UTF-8"));

      String md5 = new String(Hex.encodeHex(digest.digest()));
      sdb01.add(new Pair<byte[], byte[]>(s, (md5 + "|s").getBytes("UTF-8")));
      sdb01.add(new Pair<byte[], byte[]>(p, (md5 + "|p").getBytes("UTF-8")));
      sdb01.add(new Pair<byte[], byte[]>(o, (md5 + "|o").getBytes("UTF-8")));
      if (g != null) sdb01.add(new Pair<byte[], byte[]>(g, (md5 + "|g").getBytes("UTF-8")));
    } catch (UnsupportedEncodingException e) {
      throw new AtlasException(e);
    }

    monitor.tick();
  }
  @Override
  public void compute(Quad quad) {

    logger.debug("Computing : {} ", quad.asTriple().toString());

    String predicate = quad.getPredicate().getURI();

    if (!(predicate.equals(RDF.type))) {
      if ((quad.getSubject().isURI()) && (!(quad.getSubject().isBlank()))) {
        boolean isAdded = fqurisReservoir.add(quad.getSubject().getURI());
        logger.trace(
            "URI found on subject: {}, was added to reservoir? {}",
            quad.getSubject().getURI(),
            isAdded);
      }
    }
  }
示例#4
0
 public static void outputPlain(IndentedWriter out, Quad qp, SerializationContext naming) {
   output(out, qp.getGraph(), naming);
   out.print(" ");
   output(out, qp.getSubject(), naming);
   out.print(" ");
   output(out, qp.getPredicate(), naming);
   out.print(" ");
   output(out, qp.getObject(), naming);
 }
 public static String str(Quad q) {
   return serialize(q.getGraph())
       + " "
       + serialize(q.getSubject())
       + " "
       + serialize(q.getPredicate())
       + " "
       + serialize(q.getObject());
 }
  public void compute(Quad quad) {
    //		logger.debug("Assessing {}", quad.asTriple().toString());

    Node predicate = quad.getPredicate(); // retrieve predicate
    Node object = quad.getObject(); // retrieve object

    // checking if classes are found in the property position
    //		logger.info("Is the used predicate {} actually a class?", predicate.getURI());
    this.totalPropertiesCount++;
    if (seenProperties.containsKey(predicate.toString())) {
      if (!(seenProperties.get(predicate.toString()))) {
        this.misplacedPropertiesCount++;
        this.createProblemModel(quad.getSubject(), predicate, DQM.MisplacedClass);
      }
    } else {
      if ((VocabularyLoader.isClass(predicate)) && (VocabularyLoader.checkTerm(predicate))) {
        this.misplacedPropertiesCount++;
        this.createProblemModel(quad.getSubject(), predicate, DQM.MisplacedClass);
        seenProperties.put(predicate.toString(), false);
      }
      seenProperties.put(predicate.toString(), true);
    }

    // checking if properties are found in the object position
    if ((object.isURI())
        && (predicate.getURI().equals(RDF.type.getURI()))
        && (VocabularyLoader.checkTerm(object))) {
      //			logger.info("Checking {} for misplaced class", object.getURI());
      this.totalClassesCount++;
      if (seenClasses.containsKey(object.toString())) {
        if (!(seenClasses.get(object.toString()))) {
          this.misplacedClassesCount++;
          this.createProblemModel(quad.getSubject(), object, DQM.MisplacedProperty);
        }
      } else {
        if (VocabularyLoader.isProperty(object)) {
          this.misplacedClassesCount++;
          this.createProblemModel(quad.getSubject(), object, DQM.MisplacedProperty);
          seenClasses.put(object.toString(), false);
        }
        seenClasses.put(object.toString(), true);
      }
    }
  }
示例#7
0
    private void outputTripleOfQuad(Quad quad) {
      String s = FmtUtils.stringForNode(quad.getSubject(), sCxt);
      String p = FmtUtils.stringForNode(quad.getPredicate(), sCxt);
      String o = FmtUtils.stringForNode(quad.getObject(), sCxt);

      out.print(s);
      out.print(" ");
      out.print(p);
      out.print(" ");
      out.print(o);
    }
  public static Quad substitute(Quad quad, Binding binding) {
    if (isNotNeeded(binding)) return quad;

    Node g = quad.getGraph();
    Node s = quad.getSubject();
    Node p = quad.getPredicate();
    Node o = quad.getObject();

    Node g1 = substitute(g, binding);
    Node s1 = substitute(s, binding);
    Node p1 = substitute(p, binding);
    Node o1 = substitute(o, binding);

    Quad q = quad;
    if (s1 != s || p1 != p || o1 != o || g1 != g) q = new Quad(g1, s1, p1, o1);
    return q;
  }
  @Override
  public void compute(Quad quad) {
    logger.debug("Computing : {} ", quad.asTriple().toString());

    Node subject = quad.getSubject();
    Node object = quad.getObject();

    if (quad.getObject().equals(FOAF.Document.asNode())) {
      docs.putIfAbsent(subject.toString(), new DigitalSignature());
    }

    if (quad.getPredicate().equals(ASSURANCE.asNode())) {
      DigitalSignature ds;
      if (endorsements.containsKey(object.getURI())) {
        ds = endorsements.get(object.getURI());
      } else {
        ds = new DigitalSignature();
        ds.endorcement = object.getURI();
      }

      ds.assurance = subject.getURI();

      docs.put(subject.toString(), ds);
      endorsements.put(object.getURI(), ds);
    }

    if (quad.getPredicate().equals(ENDORSER.asNode())) {
      DigitalSignature ds;
      if (endorsements.containsKey(object.getURI())) {
        ds = endorsements.get(object.getURI());
      } else {
        ds = new DigitalSignature();
        ds.endorcement = subject.getURI();
      }

      ds.endorcer = object.getURI();
    }

    if (quad.getObject().equals(ENDORSEMENT.asNode())) {
      DigitalSignature ds = new DigitalSignature();
      ds.endorcement = subject.getURI();

      endorsements.putIfAbsent(subject.getURI(), ds);
    }
  }
  /**
   * Processes each triple obtained from the dataset to be assessed (instance declarations, that is,
   * triples with predicate rdf:type are ignored). Identifies URIs appearing in both, the subject
   * and object of the triple and adds them to the set of URIs to be evaluated for
   * dereferenceability
   *
   * @param quad Triple (in quad format) to be evaluated
   */
  public void compute(Quad quad) {
    logger.debug("Assessing {}", quad.asTriple().toString());

    // we are currently ignoring triples ?s a ?o
    if (!(quad.getPredicate().getURI().equals(RDF.type.getURI()))) {

      String subject = quad.getSubject().toString();
      if (httpRetriever.isPossibleURL(subject)) {
        logger.trace("URI found on subject: {}", subject);
        addUriToDereference(subject);
      }

      String object = quad.getObject().toString();
      if (httpRetriever.isPossibleURL(object)) {
        logger.trace("URI found on object: {}", object);
        addUriToDereference(object);
      }
    }
  }
  @Override
  public void compute(Quad quad) {
    logger.debug("Assessing {}", quad.asTriple().toString());
    Node predicate = quad.getPredicate();
    Node object = quad.getObject();

    // is it an identification of an Agent?
    if (predicate.hasURI(PROV.wasAttributedTo.getURI())) {
      Entity e = this.getOrPutEntity(quad.getSubject().toString());
      e.agent = quad.getObject().toString();
    }

    // is it an activity in an entity?
    if (predicate.hasURI(PROV.wasGeneratedBy.getURI())) {
      Activity a = this.getOrPutActivity(quad.getObject().toString());
      activityDirectory.put(quad.getSubject().toString(), a);
      Entity e = this.getOrPutEntity(quad.getSubject().toString());
      e.activities.add(a);
    }

    // is it an identification of a datasource in an activity?
    if (predicate.hasURI(PROV.used.getURI())) {
      Activity a = this.getOrPutActivity(quad.getSubject().toString());
      a.datasource = quad.getObject().toString();
    }

    // is it an identification of an agent in an activity?
    if (predicate.hasURI(PROV.wasAssociatedWith.getURI())
        || predicate.hasURI(PROV.actedOnBehalfOf.getURI())) {
      Activity a = null;
      a = this.getOrPutActivity(quad.getSubject().toString());
      a.agent = quad.getObject().getURI();
    }

    // is it an entity?
    if (object.hasURI(PROV.Entity.getURI())) {
      this.getOrPutEntity(quad.getSubject().toString());
    }

    // is it an activity?
    if (object.hasURI(PROV.Activity.getURI())) {
      this.getOrPutActivity(quad.getSubject().toString());
    }
  }
  /**
   * Builds up the RDF model "r2ml" representing the R2RML structure of the given Sparqlify-ML
   * definitions. At this point only parts of the Sparqlify-ML view definitions are considered.
   * These are so called patterns representing quads (graph, subject, predicate, object) that can be
   * valid resources or variables with certain restrictions derived from Sparqlify-ML expressions
   * like "uri(concat("http://panlex.org/plx/", ?li))" meaning that the actual value is constructed
   * by creating a URI based on the concatenation of "http://panlex.org/plx/" and the value of the
   * "li" column in the current line of the table and database at hand.
   *
   * @param r2rml the target com.hp.hpl.jena.rdf.model.Model
   * @param pattern a quad that may contain variables in the subject, predicate or object position
   * @param relation the considered database table or constructed logical relation defined by a
   *     query or view
   * @param varDefs the construction definition of the target value based in the actual database
   *     value and some additional data like prefix strings or certain functions like uri( ... )
   */
  private void exportPattern(Model r2rml, Quad pattern, SqlOpBase relation, VarDefinition varDefs) {
    /*
     * Just some hints concerning the variable names: I will give my best to
     * be as consistent as possible obeying the following rules:
     * - there is always a scope of a triple that defines the current
     *   subject predicate and object
     * - since triples can be nested it may be ambiguous what the
     *   current subject, predicate or object is
     * - since triples in R2RML refer to a subject ("rr:subjectMap"),
     *   predicate or object ("predicateObjectMap") things become even
     *   more unclear
     * - I will determine a scope based on the its subject, so if the
     *   subject is "foo", "fooSubject" is the subject in the "foo" scope.
     *   "fooPredicate" is the predicate in the "foo" scope and so on.
     * - since there may be several predicates and objects I will prefix a
     *   hint stating the special use of the considered part of a triple,
     *   so "fooPredicate_bar" is the predicate in the "foo" scope to
     *   define "bar"
     * - statements are named the same way: <scope>Statement_<use>
     */

    // create the triples map subject
    String triplesMapId = String.format("#TriplesMap%d", idCounter++);
    Resource triplesMapSubject = ResourceFactory.createResource(triplesMapId);

    // create logical table triple
    Property triplesMapPredicate_logicalTable =
        ResourceFactory.createProperty(rrNamespace + "logicalTable");

    Statement logicalTblStatement_tblDefinition = buildLogicalTableTriple(r2rml, relation);
    r2rml.add(logicalTblStatement_tblDefinition);

    Statement triplesMapStatement_logicalTable =
        r2rml.createStatement(
            triplesMapSubject,
            triplesMapPredicate_logicalTable,
            logicalTblStatement_tblDefinition.getSubject());
    r2rml.add(triplesMapStatement_logicalTable);

    /*
     * subject map
     */
    Node subjectMapObject_templColOrConst = pattern.getSubject();
    List<Statement> triplesMapStatement_subjectMaps =
        buildMapStatements(r2rml, subjectMapObject_templColOrConst, varDefs);

    // there may be more than one entry, e.g.
    // [] rr:template "http://data.example.com/department/{DEPTNO}" and
    // [] rr:class ex:Department
    for (Statement statement : triplesMapStatement_subjectMaps) {
      r2rml.add(statement);
    }

    // build up the subject map triple that looks sth. like this:
    // <#TriplesMap2> rr:subjectMap []
    if (triplesMapStatement_subjectMaps.size() > 0) {
      // rr:subjectMap
      Property triplesMapPredicate_subjectMap =
          ResourceFactory.createProperty(rrNamespace, "subjectMap");
      // []
      RDFNode triplesMapObject_subjectMap =
          (RDFNode) triplesMapStatement_subjectMaps.get(0).getSubject();
      // <#TriplesMap2> rr:subjectMap []
      Statement subjectMapTriple =
          r2rml.createStatement(
              triplesMapSubject, triplesMapPredicate_subjectMap, triplesMapObject_subjectMap);
      r2rml.add(subjectMapTriple);
    }

    /*
     * predicate map
     */
    Node predicateMap_templColOrConst = pattern.getPredicate();
    List<Statement> prediacteMapStatements =
        buildMapStatements(r2rml, predicateMap_templColOrConst, varDefs);

    // there may be more than one entry, e.g.
    // [] rr:template "http://data.example.com/department/{DEPTNO}" and
    // [] rr:class ex:Department
    for (Statement statement : prediacteMapStatements) {
      r2rml.add(statement);
    }

    /*
     * object map
     */
    Node objectMap_templColOrConst = pattern.getObject();
    List<Statement> objectMapStatements =
        buildMapStatements(r2rml, objectMap_templColOrConst, varDefs);

    // there may be more than one entry, e.g.
    // [] rr:template "http://data.example.com/department/{DEPTNO}" and
    // [] rr:class ex:Department
    for (Statement statement : objectMapStatements) {
      r2rml.add(statement);
    }

    /*
     * predicate object map
     */
    // build the predicate-object map triple that may look like this:
    // <#TriplesMap2> rr:prediacteObjectMap
    //			[ rr:predicateMap
    //					[ rr:constant
    //							ex:name
    //					] ;
    // 			  rr:objectMap
    //					[ rr:column "ENAME"
    //					];
    // 			]

    // [#1]
    Resource triplesMapObject_predicateObjectMap = ResourceFactory.createResource();

    // 1) the statement for [#1] rr:predicateMap [#2]
    Property predicateObjectMapPredicate_predicateMap =
        ResourceFactory.createProperty(rrNamespace, "predicateMap");
    // [#2]
    RDFNode predicateObjectMapObject_predicateMap =
        (RDFNode) prediacteMapStatements.get(0).getSubject();

    Statement predicateObjectMapStatement_predicateMap =
        r2rml.createStatement(
            triplesMapObject_predicateObjectMap,
            predicateObjectMapPredicate_predicateMap,
            predicateObjectMapObject_predicateMap);

    r2rml.add(predicateObjectMapStatement_predicateMap);

    // 2) the statement for [#1] rr:objectMap [#3]
    Property prediacteObjectMapPrediacte_objectMap =
        ResourceFactory.createProperty(rrNamespace, "objectMap");
    // [#3]
    RDFNode prediacteObjectMapObject_objectMap = (RDFNode) objectMapStatements.get(0).getSubject();

    Statement predicateObjectMapStatement_objectMap =
        r2rml.createStatement(
            triplesMapObject_predicateObjectMap,
            prediacteObjectMapPrediacte_objectMap,
            prediacteObjectMapObject_objectMap);

    r2rml.add(predicateObjectMapStatement_objectMap);

    // 3) the statement for <#TriplesMap2> rr:prediacteObjectMap [#1]
    Property triplesMapPredicate_predicateObjectMap =
        ResourceFactory.createProperty(rrNamespace, "predicateObjectMap");

    Statement triplesMapStatement_predicateObjectMap =
        r2rml.createStatement(
            triplesMapSubject,
            triplesMapPredicate_predicateObjectMap,
            triplesMapObject_predicateObjectMap);

    r2rml.add(triplesMapStatement_predicateObjectMap);
  }
示例#13
0
 @Override
 public Iterator<Quad> find(Quad arg0) {
   return find(arg0.getSubject(), arg0.getPredicate(), arg0.getObject(), arg0.getGraph());
 }
示例#14
0
 @Override
 public void delete(Quad arg0) {
   getGraphFor(arg0).delete(new Triple(arg0.getSubject(), arg0.getPredicate(), arg0.getObject()));
 }
示例#15
0
 @Override
 public boolean contains(Quad arg0) {
   return getGraphFor(arg0)
       .contains(new Triple(arg0.getSubject(), arg0.getPredicate(), arg0.getObject()));
 }