/** Finishes the handles mimetype filter */
 private void finishHandlesMimetypes() {
   if (handlesMimetypes != null && !handlesMimetypes.getElements().isEmpty()) {
     if (handlesMimetypes.getElements().size() > 1) {
       query.addElement(handlesMimetypes);
     } else {
       query.addElement(handlesMimetypes.getElements().get(0));
     }
   }
 }
 /** Finishes the source migration path filter. */
 private void finishMigrationPathSource() {
   if (migrationPathSource != null && !migrationPathSource.getElements().isEmpty()) {
     if (migrationPathSource.getElements().size() > 1) {
       query.addElement(migrationPathSource);
     } else {
       query.addElement(migrationPathSource.getElements().get(0));
     }
   }
 }
    /**
     * Adds a handlesMimetypes restriction to the query.
     *
     * <p>Note that all mimetypes added using the methods {@link #addHandlesMimetype(String...)},
     * {@link #addHandlesMimetypeWildcard(String...)}, {@link #addHandlesMimetypes(String, String)}
     * and {@link #addHandlesMimetypesWildcard(String, String)} will be concatenated using UNION.
     *
     * @param leftMimetype the left mimetype
     * @param rightMimetype the right mimetype
     * @return this query
     */
    public ComponentQuery addHandlesMimetypes(String leftMimetype, String rightMimetype) {
      if (leftMimetype != null
          && !leftMimetype.isEmpty()
          && rightMimetype != null
          && !rightMimetype.isEmpty()) {
        Node node = NodeFactory.createAnon();
        ElementGroup group = new ElementGroup();
        group.addTriplePattern(
            new Triple(wfNode, NodeFactory.createURI(ONTOLOGY_IRI + "handlesMimetypes"), node));
        group.addTriplePattern(
            new Triple(
                node,
                NodeFactory.createURI(TYPE_IRI),
                NodeFactory.createURI(ONTOLOGY_IRI + "AcceptedMimetypes")));
        group.addTriplePattern(
            new Triple(
                node,
                NodeFactory.createURI(ONTOLOGY_IRI + "handlesLeftMimetype"),
                NodeFactory.createLiteral(leftMimetype)));
        group.addTriplePattern(
            new Triple(
                node,
                NodeFactory.createURI(ONTOLOGY_IRI + "handlesRightMimetype"),
                NodeFactory.createLiteral(rightMimetype)));

        handlesMimetypes.addElement(group);
      }
      return this;
    }
예제 #4
0
  public NLGElement getNLFromSingleClause(Element e) {
    if (e instanceof ElementPathBlock) {
      ElementPathBlock epb = (ElementPathBlock) e;
      List<Triple> triples = new ArrayList<Triple>();

      // get all triples. We assume that the depth of union is always 1
      for (TriplePath tp : epb.getPattern().getList()) {
        Triple t = tp.asTriple();
        triples.add(t);
      }
      return getNLForTripleList(triples, "and");
    } // if clause is union clause then we generate or statements
    else if (e instanceof ElementUnion) {
      CoordinatedPhraseElement cpe;
      // cast to union
      ElementUnion union = (ElementUnion) e;
      List<Triple> triples = new ArrayList<Triple>();

      // get all triples. We assume that the depth of union is always 1
      for (Element atom : union.getElements()) {
        ElementPathBlock epb = ((ElementPathBlock) (((ElementGroup) atom).getElements().get(0)));
        if (!epb.isEmpty()) {
          Triple t = epb.getPattern().get(0).asTriple();
          triples.add(t);
        }
      }
      return getNLForTripleList(triples, "or");
    } // if it's a filter
    else if (e instanceof ElementFilter) {
      SPhraseSpec p = nlgFactory.createClause();
      ElementFilter filter = (ElementFilter) e;
      Expr expr = filter.getExpr();
      return getNLFromSingleExpression(expr);
    }
    return null;
  }
 /**
  * Adds a handlesMimetype restriction to the query.
  *
  * <p>Note that all mimetypes added using the methods {@link #addHandlesMimetype(String...)},
  * {@link #addHandlesMimetypeWildcard(String...)}, {@link #addHandlesMimetypes(String, String)}
  * and {@link #addHandlesMimetypesWildcard(String, String)} will be concatenated using UNION.
  *
  * @param mimetypes the mimetypes
  * @return this query
  */
 public ComponentQuery addHandlesMimetype(String... mimetypes) {
   if (mimetypes != null && mimetypes.length > 0) {
     ElementGroup elements = new ElementGroup();
     Set<String> mimeset = new HashSet<String>();
     Collections.addAll(mimeset, mimetypes);
     for (String mimetype : mimeset) {
       if (mimetype != null) {
         elements.addTriplePattern(
             new Triple(
                 wfNode,
                 NodeFactory.createURI(ONTOLOGY_IRI + "handlesMimetype"),
                 NodeFactory.createLiteral(mimetype)));
       }
     }
     handlesMimetypes.addElement(elements);
   }
   return this;
 }
 /**
  * Adds a migration path source restriction to the query.
  *
  * <p>Note that all mimetypes added using the methods {@link #addMigrationPath(String)}, {@link
  * #addMigrationPathWildcard(String)} will be concatenated using UNION.
  *
  * @param sourceMimetype the source mimetype
  * @return this query
  */
 public ComponentQuery addMigrationPath(String sourceMimetype) {
   if (sourceMimetype != null && !sourceMimetype.isEmpty()) {
     Node node = NodeFactory.createAnon();
     ElementGroup group = new ElementGroup();
     group.addTriplePattern(
         new Triple(wfNode, NodeFactory.createURI(ONTOLOGY_IRI + "migrates"), node));
     group.addTriplePattern(
         new Triple(
             node,
             NodeFactory.createURI(TYPE_IRI),
             NodeFactory.createURI(ONTOLOGY_IRI + "MigrationPath")));
     group.addTriplePattern(
         new Triple(
             node,
             NodeFactory.createURI(ONTOLOGY_IRI + "sourceMimetype"),
             NodeFactory.createLiteral(sourceMimetype)));
     migrationPathSource.addElement(group);
   }
   return this;
 }