Пример #1
0
  /**
   * Takes a concept and adds
   *
   * @return
   */
  public static Concept createPropertyQuery(Concept concept) {
    Collection<Var> vars = PatternVars.vars(concept.getElement());
    List<String> varNames = VarUtils.getVarNames(vars);

    Var s = concept.getVar();

    Generator gen = GeneratorBlacklist.create("v", varNames);
    Var p = Var.alloc(gen.next());
    Var o = Var.alloc(gen.next());

    Triple triple = new Triple(s, p, o);

    BasicPattern bp = new BasicPattern();
    bp.add(triple);

    List<Element> elements;
    if (concept.isSubjectConcept()) {
      elements = new ArrayList<Element>();
    } else {
      elements = concept.getElements();
    }
    elements.add(new ElementTriplesBlock(bp));

    Concept result = new Concept(elements, p);

    return result;
  }
Пример #2
0
  public void visit(OpProject opProject) {
    Configuration conf = new Configuration();
    FileSystem fs = null;
    try {
      fs = FileSystem.get(conf);
      Path out = new Path("output");
      if (!fs.exists(out)) {
        fs.delete(out, true);
        fs.mkdirs(out);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    // Iterator<Triple> it = opBGP.getPattern().getList().iterator();
    /*String[] Q1 = new String[opBGP.getPattern().getList().size()];
    int i =0;
    while(it.hasNext()){
    	Triple t = it.next();
    	Q1[i]=t.getSubject().toString(false)+"$^^$"+t.getPredicate().toString(false)+"$^^$"+t.getObject().toString(false);
       	System.out.print(t.getSubject().toString(false));
       	System.out.print(t.getPredicate().toString(false));
       	System.out.print(t.getObject().toString(false));
       	System.out.println();
       	i++;
    }*/

    /*Object[] Qo = opBGP.getPattern().getList().toArray();
      	String[] Q = new String[Qo.length];
      	for (int i = 0; i < Qo.length; i++) {
          	System.out.println(Qo[i].toString());
      		Q[i]=Qo[i].toString();
    }*/

    /*Iterator<Var> it2 = vars.iterator();
    String[] vs = new String[vars.size()];
    i =0;
    while(it2.hasNext()){
    	Var v = it2.next();
    	vs[i]=v.toString();
    	i++;
    	//System.out.println(v.toString());
    }*/

    // Set<Var> vars=query.getQueryPattern().varsMentioned(); deprecated
    /*Object[] v1 = vars.toArray();
      	String[] vs = new String[v1.length];
      	for (int i = 0; i < v1.length; i++) {
          	System.out.println(v1[i].toString());
    	vs[i]=v1[i].toString();
    }*/

    Triple[] Q = new Triple[0];
    Q = opBGP.getPattern().getList().toArray(Q);
    Set<Var> vars = PatternVars.vars(query.getQueryPattern());

    JoinPlaner.setid(id);
    JoinPlaner.newVaRS(vars);
    try {
      JoinPlaner.form(Q);
      JoinPlaner.removeNonJoiningVaribles(Q);
      int i = 0;
      while (!JoinPlaner.isEmpty()) {
        String v = JoinPlaner.getNextJoin();
        System.out.println(v);
        i++;
      }
      if (i == 0) {
        Path outFile = new Path("output/Join_" + id + "_" + 0);
        if (fs.exists(outFile)) {
          fs.delete(outFile, true);
        }
        QueryProcessor.executeSelect(Q[0], fs.create(outFile), "P0");
      }
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }