コード例 #1
0
  public Instance getInstance(Identifier id, Concept concept) {
    reasoner.deRegisterOntology((IRI) (state.getIdentifier()));
    try {
      reasoner.registerOntology(state);
    } catch (InconsistencyException e) {
      logger.warn("Ontology registration failed.", e);
    }
    Set<Instance> instances = reasoner.getInstances((IRI) state.getIdentifier(), concept);
    Instance instance = null;
    for (Instance i : instances) if (i.getIdentifier().equals(id)) instance = i;
    for (Entry<Molecule, Axiom> e : axioms.entrySet()) {
      if (e.getKey() instanceof AttributeValueMolecule) {
        AttributeValueMolecule avm = (AttributeValueMolecule) e.getKey();
        Axiom axiom = e.getValue();

        if (avm.getLeftParameter().equals(instance.getIdentifier())) {
          try {
            instance.addAttributeValue((IRI) avm.getAttribute(), (Value) avm.getRightParameter());
          } catch (Exception e2) {
            logger.warn("Failed to pseudo-reason.", e2);
          }
        }
      }
    }

    return instance;
  }
コード例 #2
0
 public CompoundFact copy(CompoundFact fact) throws ParserException {
   // FIXME reliance on toString()
   MembershipMolecule mm = null;
   MoleculeFact mf = (MoleculeFact) fact; // FIXME handle relation facts);
   if (mf.listMembershipMolecules().size() > 0)
     mm =
         (MembershipMolecule)
             leFactory.createLogicalExpression(
                 mf.listMembershipMolecules().iterator().next().toString());
   Set<AttributeValueMolecule> avms = new HashSet<AttributeValueMolecule>();
   for (AttributeValueMolecule avm : mf.listAttributeValueMolecules()) {
     avms.add((AttributeValueMolecule) leFactory.createLogicalExpression(avm.toString()));
   }
   // TODO write this more elegant once factory convenience creators are fixed
   Set<MembershipMolecule> mms = new HashSet<MembershipMolecule>();
   if (mf.listMembershipMolecules().size() > 0) mms.add(mm);
   return cFactory.facts.createMoleculeFact(mms, avms);
 }