Exemple #1
0
 /** Create a Context from content of st:param */
 public Context process() {
   Entity ent = g.getEdges(Context.STL_PARAM).iterator().next();
   if (ent == null) {
     return new Context();
   }
   return process(ent.getNode(1));
 }
Exemple #2
0
 int compare(Entity ent, Node n1, Node n2) {
   int res = nodeCompare(getNode(ent, index), n1);
   if (res == 0 && n2 != null) {
     res = nodeCompare(ent.getNode(other), n2);
   }
   return res;
 }
Exemple #3
0
 int compare(Entity ent, int n1, int n2) {
   int res = compare(getNode(ent, index).getIndex(), n1);
   if (res == 0) {
     res = compare(ent.getNode(other).getIndex(), n2);
   }
   return res;
 }
Exemple #4
0
  void context(Node ctx) {
    importer(ctx);

    for (Entity ent : g.getEdgeList(ctx)) {
      if (!ent.getEdge().getLabel().equals(Context.STL_IMPORT)) {
        Node object = ent.getNode(1);

        if (object.isBlank()) {
          IDatatype list = list(g, object);
          if (list != null) {
            c.set(ent.getEdge().getLabel(), list);
            continue;
          }
        }
        c.set(ent.getEdge().getLabel(), (IDatatype) object.getValue());
      }
    }
  }
Exemple #5
0
 /** Written for index = 0 */
 public boolean exist(Node pred, Node n1, Node n2) {
   List<Entity> list = checkGet(pred);
   if (list == null) {
     return false;
   }
   int n;
   if (isByIndex()) {
     n = find(list, n1.getIndex(), n2.getIndex(), 0, list.size());
   } else {
     n = find(list, n1, n2, 0, list.size());
   }
   if (n >= 0 && n < list.size()) {
     Entity ent = list.get(n);
     if (same(n1, ent.getNode(0)) && same(n2, ent.getNode(1))) {
       return true;
     }
   }
   return false;
 }
Exemple #6
0
 /**
  * Create the index of property pred on nth argument It is synchronized on pred hence several
  * synGetCheck can occur in parallel on different pred
  */
 private List<Entity> synCheckGet(Node pred) {
   synchronized (pred) {
     ArrayList<Entity> list = get(pred);
     if (list != null && list.size() == 0) {
       List<Entity> std = (List<Entity>) graph.getIndex().getEdges(pred, null);
       list.ensureCapacity(std.size());
       if (index < 2) {
         // we are sure that there are at least 2 nodes
         list.addAll(std);
       } else
         for (Entity ent : std) {
           // if additional node is missing: do not index this edge
           if (ent.nbNode() > index) {
             list.add(ent);
           }
         }
       index(pred);
     }
     return list;
   }
 }
Exemple #7
0
  public boolean exist(Entity edge) {
    if (index != IGRAPH && edge.nbNode() <= index) {
      // use case:  additional node is not present, do not index on this node
      // never happens for subject object and graph
      return false;
    }
    List<Entity> list = getByLabel(edge);
    if (list == null) return false;
    int i = find(list, edge, 0, list.size());

    if (i >= list.size()) {
      return false;
    }

    int res = comp.compare(edge, list.get(i));
    return (res == 0);
  }
Exemple #8
0
  public Entity delete(Entity edge) {
    if (index != IGRAPH && edge.nbNode() <= index) {
      // use case:  additional node is not present, do not index on this node
      // never happens for subject object and graph
      return null;
    }
    List<Entity> list = getByLabel(edge);
    if (list == null) return null;

    Comparator<Entity> cmp = getComp();

    int i = find(cmp, list, edge, 0, list.size());

    if (i >= list.size()) {
      return null;
    }

    if (graph.hasTag()) {
      // if edge have no tag:
      // dichotomy may have jump in the middle of the tag list
      // find first edge of the list
      while (i > 0 && cmp.compare(list.get(i - 1), edge) == 0) {
        i--;
      }
    }

    Entity ent = delete(cmp, edge, list, i);

    logDelete(ent);

    if (graph.hasTag()) {
      // delete all occurrences of triple that match edge
      // with different tags
      Entity res = ent;
      while (i < list.size() && res != null) {
        res = delete(cmp, edge, list, i);
        logDelete(res);
      }
    }
    return ent;
  }
Exemple #9
0
 public void declare(Entity edge, boolean duplicate) {
   List<Entity> list = define(edge.getEdge().getEdgeNode());
   if (list.size() > 0) {
     add(edge, duplicate);
   }
 }
Exemple #10
0
 /** delete/exist */
 List<Entity> getByLabel(Entity e) {
   Node pred = graph.getPropertyNode(e.getEdge().getEdgeNode().getLabel());
   if (pred == null) return null;
   List<Entity> list = get(pred);
   return list;
 }
Exemple #11
0
 // TBD
 boolean same(Entity e1, Entity e2) {
   return e1.getNode(0).same(e2.getNode(0)) && e1.getNode(1).same(e2.getNode(1));
 }
Exemple #12
0
  /** noGraph == true => if edge already exists in another graph, do not add edge */
  public Entity add(Entity edge, boolean duplicate) {
    if (index != IGRAPH && edge.nbNode() <= index) {
      // use case:  additional node is not present, do not index on this node
      // never happens for subject object and graph
      return null;
    }

    List<Entity> list = define(edge.getEdge().getEdgeNode());

    Comparator cc = comp;

    boolean needTag = index == 0 && graph.needTag(edge);
    if (needTag) {
      // this edge has no tag yet and it will need onefind
      // let's see if there is the same triple (with another tag)
      // in this case, we skip the insertion
      // otherwise we tag the triple and we insert it
      cc = skipTag;
    } else if (!duplicate) {
      cc = skipGraph;
    }

    if (isSort(edge)) {
      // edges are sorted, check presence by dichotomy
      int i = find(cc, list, edge, 0, list.size());
      int res = 0;

      if (i >= list.size()) {
        i = list.size();
      } else {
        if (index == 0) {
          res = cc.compare(edge, list.get(i));
          if (res == 0) {
            // eliminate duplicate at load time for index 0
            count++;
            return null;
          }
        }
      }

      if (needTag) {
        tag(edge);
      }

      if (onInsert(edge)) {
        list.add(i, edge);
        logInsert(edge);
      } else {
        return null;
      }

    } else {
      // edges are not already sorted (load time)
      // add all edges, duplicates will be removed later when first query occurs
      if (onInsert(edge)) {
        list.add(edge);
        logInsert(edge);
      } else {
        return null;
      }
    }

    // complete(edge);
    return edge;
  }
Exemple #13
0
 Node getNode(Entity ent, int n) {
   if (n == IGRAPH) {
     return ent.getGraph();
   }
   return ent.getNode(n);
 }
Exemple #14
0
 void add(Entity ent) {
   Edge edge = ent.getEdge();
   for (int i = 0; i < edge.nbNode(); i++) {
     add(ent.getGraph(), edge.getNode(i));
   }
 }