Archive

Archive for October, 2006

Calling Java Methods from SWRL Rules

October 10, 2006 Leave a comment

With Bossam, it’s possible to introduce Java method calls into SWRL rules. In Bossam, Java method calls are represented as SWRL builtin atoms. It’s necessary to read first about the Bossam’s mechanism of URI-based Java method call.

The namespaces related are as follows:
bossam: http://www.etri.re.kr/2003/10/bossam#
tc: java://etri.bossam.swrl/TemperatureController#
swrl: http://www.w3.org/2003/11/swrl#

bossam:serviceCall

Java method call is wrapped around a new SWRL builtin atom: bossam:serviceCall. There’re two forms of bossam:serviceCall, each of which is for object binding and method call.

Object Binding Format

The format is defined as follows:

bossam:serviceCall(java-class-sig, java-obj)

java-class-sig is the URI specification of a Java class. out-arg is bound to the Java objects in the current inference context which are of the type specified by java-class-sig.

Method Call Format

The format is defined as follows:

bossam:serviceCall(java-method-sig, java-obj, in-arg-1, in-arg-2,..., in-arg-n, out-arg)

java-method-sig is the URI specification of the Java method to call. java-obj refers to the Java objects for which the method call shall be made. in-arg-1,...,in-arg-n are input arguments for the method. Not necessary to specify if method has no input parameters. out-arg is bound to the result of the method call. Not necessary to specify if method has no output.

Sample 1: Binding Java objects

The following code binds to the instances of etri.bossam.swrl.TemperatureController to the variable ?o.

<swrl:BuiltinAtom>
  <swrl:builtin rdf:resource="&bossam;#serviceCall"/>
    <swrl:arguments>
      <rdf:List>
        <rdf:first rdf:resource="&tc;#class"/>
        <rdf:rest>
          <rdf:List>
            <rdf:first rdf:resource="#o" />
            <rdf:rest rdf:resource="&rdf;#nil"/>
          </rdf:List>
        </rdf:rest>
      </rdf:List>
    </swrl:arguments>
</swrl:BuiltinAtom>

Sample 2: Calling a Getter Method With No Input Argument

The following code calls the method getTemperature() on the instances of etri.bossam.swrl.TemperatureController, and binds the results to the variable ?v.

<swrl:BuiltinAtom>
  <swrl:builtin rdf:resource="&bossam;#serviceCall"/>
  <swrl:arguments>
    <rdf:List>
      <rdf:first rdf:resource="&tc;#getTemperature"/>
      <rdf:rest>
        <rdf:List>
          <rdf:first rdf:resource="#o" />
          <rdf:rest>
            <rdf:List>
              <rdf:first rdf:resource="#v" />
              <rdf:rest rdf:resource="&rdf;#nil"/>
            </rdf:List>
          </rdf:rest>
        </rdf:List>
      </rdf:rest>
    </rdf:List>
  </swrl:arguments>
</swrl:BuiltinAtom>

Sample 3: Calling a Getter Method With Input Arguments

The following code calls the method getTemperatureInFahrenheit(double) on the instances of etri.bossam.swrl.TemperatureController, and binds the results to the variable ?v.

<swrl:BuiltinAtom>
  <swrl:builtin rdf:resource="&bossam;#serviceCall"/>
  <swrl:arguments>
    <rdf:List>
      <rdf:first rdf:resource="&tc;#getTemperatureInFahrenheit"/>
      <rdf:rest>
        <rdf:List>
          <rdf:first rdf:resource="#o" />
          <rdf:rest>
            <rdf:List>
              <rdf:first rdf:datatype="&xsd;#double">10.0</rdf:first>
              <rdf:rest>
                <rdf:List>
                  <rdf:first rdf:resource="#v" />
                  <rdf:rest rdf:resource="&rdf;#nil"/>
                </rdf:List>
              </rdf:rest>
            </rdf:List>
          </rdf:rest>
        </rdf:List>
      </rdf:rest>
    </rdf:List>
  </swrl:arguments>
</swrl:BuiltinAtom>

Sample 4: Calling a Setter Method with No Input Argument

The following code calls the method turnOn() on the instances of etri.bossam.swrl.TemperatureController.

<swrl:BuiltinAtom>
  <swrl:builtin rdf:resource="&bossam;#serviceCall"/>
  <swrl:arguments>
    <rdf:List>
      <rdf:first rdf:resource="&tc;#turnOn"/>
      <rdf:rest>
        <rdf:List>
          <rdf:first rdf:resource="#o" />
          <rdf:rest rdf:resource="&rdf;#nil"/>
        </rdf:List>
      </rdf:rest>
    </rdf:List>
  </swrl:arguments>
</swrl:BuiltinAtom>
Categories: manual