Example #1
0
  public OWLNamedIndividual assertPropertyChain(
      KnowledgeHelper kh, String path, OWLNamedIndividual srcVar, String modelNS) {
    StringTokenizer tok = new StringTokenizer(path, ".");
    List<String> chain = new ArrayList<String>(tok.countTokens());
    while (tok.hasMoreTokens()) {
      chain.add(tok.nextToken());
    }
    Collections.reverse(chain);

    OWLNamedIndividual current = srcVar;
    for (int j = 0; j < chain.size(); j++) {
      String prop = chain.get(j);
      OWLNamedIndividual propCode = asIndividual(modelNS + prop);
      kh.insert(assertObjectProperty("ops:propCode", current, propCode));
      kh.insert(assertDataProperty("skos-ext:code", propCode, modelNS + prop));
      kh.insert(assertType(current, "ops:DomainPropertyExpression"));

      if (j != chain.size() - 1) {
        OWLNamedIndividual expr = asIndividual("tns:PropertyExpr_" + System.identityHashCode(prop));
        kh.insert(assertObjectProperty("ops:source", current, expr));
        current = expr;
      }
    }
    return current;
  }
Example #2
0
 public OWLNamedIndividual assertExpression(KnowledgeHelper kh, String op, Object root) {
   OWLNamedIndividual expr = asExpressionIndividual(op, root);
   OWLNamedIndividual opCode = asIndividual("ops:Op_" + op);
   kh.insert(assertObjectProperty("ops:opCode", expr, opCode));
   kh.insert(assertDataProperty("skos-ext:code", opCode, op));
   String actualOp = mapOperation(op);
   if (actualOp != null) {
     kh.insert(assertType(expr, determineNamespace(actualOp) + actualOp + "Expression"));
   }
   return expr;
 }
 @Override
 public void evaluate(KnowledgeHelper arg0, WorkingMemory arg1) throws Exception {
   InternalFactHandle a1f = arg0.getTuple().get(0);
   AbstractParameter a1 = (AbstractParameter) arg1.getObject(a1f);
   String a1Id = a1.getId();
   InternalFactHandle a2f = arg0.getTuple().get(1);
   AbstractParameter a2 = (AbstractParameter) arg1.getObject(a2f);
   Sequence<AbstractParameter> s = new Sequence<>(a1Id, 2);
   s.add(a1);
   s.add(a2);
   Segment<AbstractParameter> segment = new Segment<>(s);
   JBossRulesDerivedLocalUniqueIdValuesProvider provider =
       new JBossRulesDerivedLocalUniqueIdValuesProvider(arg1, a1Id);
   UniqueIdFactory factory = new ProviderBasedUniqueIdFactory(provider);
   AbstractParameter result = new AbstractParameter(a1Id, factory.getInstance());
   result.setSourceSystem(SourceSystem.DERIVED);
   result.setInterval(segment.getInterval());
   result.setValue(a1.getValue());
   result.setCreateDate(new Date());
   Logger logger = ProtempaUtil.logger();
   if (logger.isLoggable(Level.FINEST)) {
     logger.log(Level.FINEST, "Created {0} from {1} and {2}", new Object[] {result, a1, a2});
   }
   arg1.retract(a1f);
   arg1.retract(a2f);
   arg1.insert(result);
   // There should not be any forward derivations yet.
   // List<Proposition> a1PropForward =
   // this.derivationsBuilder.propositionRetractedForward(a1);
   List<Proposition> a1PropBackward = this.derivationsBuilder.propositionRetractedBackward(a1);
   // There should not be any forward derivations yet.
   // List<Proposition> a2PropForward =
   // this.derivationsBuilder.propositionRetractedForward(a2);
   List<Proposition> a2PropBackward = this.derivationsBuilder.propositionRetractedBackward(a2);
   for (Proposition prop : a1PropBackward) {
     this.derivationsBuilder.propositionReplaceForward(prop, a1, result);
     this.derivationsBuilder.propositionAssertedBackward(prop, result);
   }
   for (Proposition prop : a2PropBackward) {
     this.derivationsBuilder.propositionReplaceForward(prop, a2, result);
     this.derivationsBuilder.propositionAssertedBackward(prop, result);
   }
   logger.log(Level.FINER, "Asserted derived proposition {0}", result);
 }
Example #4
0
 public void assertNullSafeDataProperty(
     KnowledgeHelper drools, String property, OWLNamedIndividual src, String tgt, String type) {
   if (!"null".equals(tgt)) {
     if (type.startsWith("xsd:")) {
       // hack: using the short form
       type = IRI.create("http://www.w3.org/2001/XMLSchema#" + type.substring(4)).toString();
     } else {
       System.out.println("Unkokwn type");
     }
     drools.insert(assertTypedDataProperty(property, src, tgt, type));
   }
 }
Example #5
0
  public void assertCD(KnowledgeHelper kh, String property, OWLNamedIndividual src, Object code) {
    OWLNamedIndividual cd = asIndividual(code);
    kh.insert(assertObjectProperty(property, src, cd));
    kh.insert(assertType(cd, "skos-ext:ConceptCode"));

    String codeVal = extractStringProperty("getCode", code);
    if (codeVal != null) {
      kh.insert(assertDataProperty("skos-ext:code", cd, codeVal));
    }
    String codeSystem = extractStringProperty("getCodeSystem", code);
    if (codeSystem != null) {
      kh.insert(assertDataProperty("skos-ext:codeSystem", cd, codeSystem));
    }
    String codeSystemName = extractStringProperty("getCodeSystemName", code);
    if (codeSystemName != null) {
      kh.insert(assertDataProperty("skos-ext:codeSystemName", cd, codeSystemName));
    }
    String text = extractStringProperty("getOriginalText", code);
    if (text != null) {
      kh.insert(assertDataProperty("skos-ext:label", cd, text));
    }
  }