Example #1
0
  public static void insertSystemTriples(
      ISparulExecutor executor, String dataGraphName, String metaGraphName) throws Exception {
    logger.info("Inserting Annotation Properties.");

    List<RDFTriple> triples = new ArrayList<RDFTriple>();

    MyVocabulary[] vocabs = {
      MyVocabulary.DC_MODIFIED,
      MyVocabulary.DBM_EDIT_LINK,
      MyVocabulary.DBM_PAGE_ID,
      MyVocabulary.DBM_REVISION,
      MyVocabulary.DBM_OAIIDENTIFIER
    };

    for (MyVocabulary item : vocabs) {
      triples.add(
          new RDFTriple(
              new RDFResourceNode(item.getIRI()),
              new RDFResourceNode(OWLRDFVocabulary.RDF_TYPE.getIRI()),
              new RDFResourceNode(OWLRDFVocabulary.OWL_ANNOTATION_PROPERTY.getIRI())));
    }

    List<RDFTriple> metaTriples = new ArrayList<RDFTriple>();
    for (RDFTriple item : triples) {
      URI uri = RDFUtil.generateMD5HashUri("http://dbpedia.org/sysvocab/", item);

      RDFResourceNode reifier = new RDFResourceNode(IRI.create(uri));

      metaTriples.add(
          new RDFTriple(
              reifier,
              new RDFResourceNode(OWLRDFVocabulary.OWL_ANNOTATED_SOURCE.getIRI()),
              item.getSubject()));
      metaTriples.add(
          new RDFTriple(
              reifier,
              new RDFResourceNode(OWLRDFVocabulary.OWL_ANNOTATED_PROPERTY.getIRI()),
              item.getProperty()));
      metaTriples.add(
          new RDFTriple(
              reifier,
              new RDFResourceNode(OWLRDFVocabulary.OWL_ANNOTATED_TARGET.getIRI()),
              item.getObject()));
      metaTriples.add(
          new RDFTriple(
              reifier,
              new RDFResourceNode(MyVocabulary.DBM_EXTRACTED_BY.getIRI()),
              new RDFResourceNode(IRI.create(TBoxExtractor.extractorUri))));
    }

    executor.insert(metaTriples, metaGraphName);
    executor.insert(triples, dataGraphName);
  }
  /**
   * Renders the triples whose subject is the specified node
   *
   * @param node The node
   */
  @Override
  public void render(RDFResourceNode node) {
    level++;
    if (pending.contains(node)) {
      // We essentially remove all structure sharing during parsing - any cycles therefore indicate
      // a bug!
      throw new IllegalStateException(
          "Rendering cycle!  This indicates structure sharing and should not happen!");
    }
    pending.add(node);
    Set<RDFTriple> triples = new TreeSet<RDFTriple>(new TripleComparator());
    triples.addAll(getGraph().getTriplesForSubject(node));

    RDFResourceNode lastSubject = null;
    RDFResourceNode lastPredicate = null;
    boolean first = true;
    for (RDFTriple triple : triples) {
      RDFResourceNode subj = triple.getSubject();
      RDFResourceNode pred = triple.getProperty();
      if (lastSubject != null && (subj.equals(lastSubject) || subj.isAnonymous())) {
        if (lastPredicate != null && pred.equals(lastPredicate)) {
          // Only the object differs from previous triple
          // Just write the object
          write(" ,");
          writeNewLine();
          write(triple.getObject());
        } else {
          // The predicate, object differ from previous triple
          // Just write the predicate and object
          write(" ;");
          popTab();
          if (!subj.isAnonymous()) {
            writeNewLine();
          }
          writeNewLine();
          write(triple.getProperty());
          write(" ");
          pushTab();
          write(triple.getObject());
        }
      } else {
        if (!first) {
          popTab();
          popTab();
          writeNewLine();
        }
        // Subject, preficate and object are different from last triple
        if (!node.isAnonymous()) {
          write(triple.getSubject());
          write(" ");
        } else {
          pushTab();
          write("[");
          write(" ");
        }
        pushTab();
        write(triple.getProperty());
        write(" ");
        pushTab();
        write(triple.getObject());
      }
      lastSubject = subj;
      lastPredicate = pred;
      first = false;
    }

    if (node.isAnonymous()) {
      popTab();
      popTab();
      if (triples.isEmpty()) {
        write("[ ");
      } else {
        writeNewLine();
      }
      write("]");
      popTab();
    } else {
      popTab();
      popTab();
    }
    if (level == 1 && !triples.isEmpty()) {
      write(" .\n");
    }
    writer.flush();

    pending.remove(node);
    level--;
  }