Search code examples
expressionswrl

OWL-S Precondition expression extracting


I am trying to extract the precondition's expression as SWRL to make a IOPE web service OWL-S matchmaking

Here's my code

final OWLIndividualList<Condition> cs = service.getProcess().getConditions();
final ArrayList<ArrayList<URI>> conditions = new ArrayList<ArrayList<URI>>();
    for (final Condition<?> c : cs){
        if (c.canCastTo(Condition.SWRL.class)){ 
            final Condition.SWRL sc = c.castTo(Condition.SWRL.class);
            for (final Atom a : sc.getBody()){
                a.accept(new AtomVisitor() {
                public void visit(final IndividualPropertyAtom atom){
                    URI aux = null;
                    final ArrayList<URI> uris = new ArrayList<URI>();
                    URI a1 = aux.create((atom.getArgument1().getNamespace().toString() 
                    +atom.getArgument1().toString()));
                    URI a2 = aux.create((atom.getArgument2().getNamespace().toString() 
                    +atom.getArgument2().toString()));
                    URI p = aux.create(atom.getPropertyPredicate().toString());
                    uris.add(p);
                    uris.add(a1);
                    uris.add(a2);
                    conditions.add(uris);
               }
               public void visit(final DataPropertyAtom atom) { }
               public void visit(final SameIndividualAtom atom) { }
               public void visit(final DifferentIndividualsAtom atom) { }
               public void visit(final ClassAtom atom) { }
               public void visit(final BuiltinAtom atom)    { }
          });
      }
  }

}

I am getting an java.lang.NullPointerException on "final Atom a : sc.getBody()"

The OWL-S precondition statement

     <expr:SWRL-Condition rdf:ID="DifferentLocations">
         <expr:expressionLanguage rdf:resource="http://www.daml.org/services/owl- 
              s/1.2/generic/Expression.owl#SWRL"/>
         <expr:expressionBody rdf:parseType="Literal">
            <swrl:AtomList>
                <rdf:first>
                    <swrl:DifferentIndividualsAtom>
                         <swrl:argument1 rdf:resource="#_GEOPOLITICAL-ENTITY"/>
                         <swrl:argument2 rdf:resource="#_GEOPOLITICAL-ENTITY1"/>
                    </swrl:DifferentIndividualsAtom>
                </rdf:first>
                <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
             </swrl:AtomList>
         </expr:expressionBody>
      </expr:SWRL-Condition>

Please I need help


Solution

  • This issue is not linked to the java code but to the OWLS-S file syntaxe. you can resolve this issue by replacing:

      <expr:expressionBody rdf:parseType="Literal">
    

    which hold the SWRL precondition (or eventually the result), by:

      <expr:expressionObject>