/**
   * Create a new RDF store using the provided Blueprints graph. Additionally, create edge indices
   * for the provided triple patterns (potentially speeding up certain queries, while increasing
   * storage overhead).
   *
   * @param graph the storage layer. If the provided graph implements TransactionalGraph and is in
   *     manual transaction mode, then this Sail will also be transactional. Any vertices and edges
   *     in the graph should have been previously created with GraphSail.
   * @param indexedPatterns a comma-delimited list of triple patterns for index-based statement
   *     matching. Only p,c are required, while the default patterns are p,c,pc.
   */
  public GraphSail(final T graph, final String indexedPatterns) {
    // if (graph instanceof TransactionalGraph)
    //    ((TransactionalGraph) graph).setTransactionMode(TransactionalGraph.Mode.AUTOMATIC);
    // printGraphInfo(graph);

    store.sail = this;
    store.graph = graph;

    createIndices(graph);

    store.manualTransactions = store.graph instanceof TransactionalGraph;
    // && 0 == ((TransactionalGraph) store.graph).getMaxBufferSize();

    store.namespaces = store.getReferenceVertex();
    if (null == store.namespaces) {
      if (store.manualTransactions) {
        ((TransactionalGraph) graph).startTransaction();
      }
      try {
        // FIXME: with FAKE_VERTEX_IDS, an extra "namespace" called "value" is present.  Perhaps
        // namespaces
        // should be given individual nodes, rather than being encapsulated in properties of the
        // namespaces node.
        store.namespaces = store.addVertex(NAMESPACES_VERTEX_ID);
      } finally {
        if (store.manualTransactions) {
          ((TransactionalGraph) graph).stopTransaction(TransactionalGraph.Conclusion.SUCCESS);
        }
      }
    }

    store.matchers[0] = new TrivialMatcher(graph);

    parseTripleIndices(indexedPatterns);
    assignUnassignedTriplePatterns();
  }
Beispiel #2
0
  public static void load(final Graph graph) {

    // vertices

    final Vertex saturn = graph.addVertex(null);
    saturn.setProperty("name", "saturn");
    saturn.setProperty("age", 10000);
    saturn.setProperty("type", "titan");
    saturn.setProperty(TYPE_RESOLUTION_KEY, God.class.getName());

    final Vertex sky = graph.addVertex(null);
    ElementHelper.setProperties(
        sky, "name", "sky", "type", "location", "other", "more useless info");

    final Vertex sea = graph.addVertex(null);
    ElementHelper.setProperties(sea, "name", "sea", "type", "location");

    final Vertex jupiter = graph.addVertex(null);
    ElementHelper.setProperties(
        jupiter,
        "name",
        "jupiter",
        "age",
        5000,
        "type",
        "god",
        TYPE_RESOLUTION_KEY,
        God.class.getName());

    final Vertex neptune = graph.addVertex(null);
    ElementHelper.setProperties(
        neptune,
        "name",
        "neptune",
        "age",
        4500,
        "type",
        "god",
        TYPE_RESOLUTION_KEY,
        God.class.getName());

    final Vertex hercules = graph.addVertex(null);
    ElementHelper.setProperties(
        hercules,
        "name",
        "hercules",
        "age",
        30,
        "type",
        "demigod",
        TYPE_RESOLUTION_KEY,
        GodExtended.class.getName());

    final Vertex alcmene = graph.addVertex(null);
    ElementHelper.setProperties(
        alcmene,
        "name",
        "alcmene",
        "age",
        45,
        "type",
        "human",
        TYPE_RESOLUTION_KEY,
        God.class.getName());

    final Vertex pluto = graph.addVertex(null);
    ElementHelper.setProperties(
        pluto,
        "name",
        "pluto",
        "age",
        4000,
        "type",
        "god",
        TYPE_RESOLUTION_KEY,
        God.class.getName());

    final Vertex nemean = graph.addVertex(null);
    ElementHelper.setProperties(
        nemean, "name", "nemean", "type", "monster", TYPE_RESOLUTION_KEY, God.class.getName());

    final Vertex hydra = graph.addVertex(null);
    ElementHelper.setProperties(
        hydra, "name", "hydra", "type", "monster", TYPE_RESOLUTION_KEY, God.class.getName());

    final Vertex cerberus = graph.addVertex(null);
    ElementHelper.setProperties(
        cerberus, "name", "cerberus", "type", "monster", TYPE_RESOLUTION_KEY, God.class.getName());

    final Vertex tartarus = graph.addVertex(null);
    ElementHelper.setProperties(
        tartarus, "name", "tartarus", "type", "location", TYPE_RESOLUTION_KEY, God.class.getName());

    // edges

    ElementHelper.setProperties(
        jupiter.addEdge("father", saturn), TYPE_RESOLUTION_KEY, FatherEdge.class.getName());
    jupiter.addEdge("lives", sky).setProperty("reason", "loves fresh breezes");
    jupiter.addEdge("brother", neptune);
    jupiter.addEdge("brother", pluto);

    ElementHelper.setProperties(
        neptune.addEdge("father", saturn), TYPE_RESOLUTION_KEY, FatherEdge.class.getName());
    neptune.addEdge("lives", sea).setProperty("reason", "loves waves");
    neptune.addEdge("brother", jupiter);
    neptune.addEdge("brother", pluto);

    ElementHelper.setProperties(
        hercules.addEdge("father", jupiter),
        TYPE_RESOLUTION_KEY,
        FatherEdgeExtended.class.getName());
    hercules.addEdge("lives", sky).setProperty("reason", "loves heights");
    ElementHelper.setProperties(hercules.addEdge("battled", nemean), "time", 1);
    ElementHelper.setProperties(hercules.addEdge("battled", hydra), "time", 2);
    ElementHelper.setProperties(hercules.addEdge("battled", cerberus), "time", 12);

    ElementHelper.setProperties(
        pluto.addEdge("father", saturn), TYPE_RESOLUTION_KEY, FatherEdge.class.getName());
    pluto.addEdge("brother", jupiter);
    pluto.addEdge("brother", neptune);
    pluto.addEdge("lives", tartarus).setProperty("reason", "no fear of death");
    pluto.addEdge("pet", cerberus);

    cerberus.addEdge("lives", tartarus);
    ElementHelper.setProperties(cerberus.addEdge("battled", alcmene), "time", 5);

    // commit the transaction to disk
    if (graph instanceof TransactionalGraph) ((TransactionalGraph) graph).commit();
  }