JASB Ξ Java Architecture for Semantic Binding

Help for Semantic Application

 »   An example

The application of the semantic features presents in OWL into object-oriented instances could be done following the next example:

We are supposing that the tbox.swrl file has been generated with our compiler and then all the semantic enrichment over the file has been done with any ontology editor as Protege or rule editor as ORE.

     public static void main(String[] args) throws ConvertionException { 
        // Registering clients 
        Person bob = new Person(); 
        bob.setName("Bob"); 
        bob.setAllergic(true); 
        Collection<Person> clients = new ArrayList<Person>(); 
        clients.add(bob); 
        // Registering available toppings 
        Topping tomato = new Topping("tomato"); 
        Topping tuna = new Topping("tuna"); 
        Topping cheese = new CheeseTopping("hypoallergic"); 
        Topping onion = new Topping("onion"); 
 
        Collection<Topping> availableToppings = new ArrayList<Topping>(); 
        availableToppings.add(cheese); 
        availableToppings.add(tomato); 
        availableToppings.add(tuna); 
        availableToppings.add(onion); 
        // Registering the request 
        CheesePizza pizza = new CheesePizza(); 
        pizza.getHasTopping().add(tomato); 
        pizza.getHasTopping().add(onion); 
        bob.getAssignedTo().add(pizza); 
        Collection<Pizza> requests = new ArrayList<Pizza>(); 
        requests.add(pizza); 
 
        // Do the semantic enrichment 
        HashMap<Class, Collection<?>> instances = new HashMap<Class, Collection<?>>(); 
        instances.put(Topping.class, availableToppings); 
        instances.put(Person.class, clients); 
        instances.put(Pizza.class, requests); 
        SemanticEnforcing se = new SemanticEnforcing(new File("tbox.swrl"), 
                "http://www.um.es/exampleB"); 
        se.doReasoningJena(instances); 
        //  se.doReasoningPelletJena(instances); 
        //se.doReasoningPellet(instances); 
        se.doReasoningPelletJess(instances); 
        System.out.println("Topping for " + bob.getName() + "'s Pizza:"); 
        for (Topping t : pizza.getHasTopping()) { 
            System.out.println("\t-" + t.getName()); 
        } 
    } 
}