/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package me.aatma.upperontology;

import me.aatma.library.sapi.jenasclient.Constants;
import me.aatma.library.sapi.jenasclient.ContextImpl;
import me.aatma.library.sapi.jenasclient.SCollectionImpl;
import me.aatma.library.sapi.Context;
import me.aatma.library.sapi.SCollection;
import me.aatma.library.sapi.exception.CreateException;
import me.aatma.library.sapi.exception.SapiTypeException;
import me.aatma.library.sapi.jenasclient.BinaryPredicateImpl;
import me.aatma.library.sapi.jenasclient.vocabulary.OWL_S;
import me.aatma.library.sapi.jenasclient.vocabulary.XSD_S;
import me.aatma.library.sapi.BinaryPredicate;
import me.aatma.library.sapi.Sentence;
import me.aatma.library.sapi.jenasclient.SObjectImpl;
import me.aatma.library.sapi.jenasclient.SentenceImpl;
import org.apache.jena.query.ReadWrite;

/**
 *
 * @author Vijay
 */
public class SocialOntologyScript {
  
  public static void main (String [] args) throws SapiTypeException, CreateException {
    createSocialOntology();
    createHumanActivitiesOntology();
  }
  
  public static void createSocialOntology() throws SapiTypeException, CreateException {
    SObjectImpl.getDataset().begin(ReadWrite.WRITE);
    
    String socialNs = Constants.TBOX_PART + "SocialVocabulary#";
    Context socialCtx = new ContextImpl(socialNs);
    
    String eventNs = Constants.TBOX_PART + "event#";
    Context eventCtx = new ContextImpl(eventNs);
    
    SCollection agent = new SCollectionImpl(eventNs + "Agent", eventCtx);
    
    socialCtx.addInheritsFromWithRuleCtx(eventCtx);
    
    // Person can be made sameAs with AnimalVocabulary (not yet created) HomoSapiens
    // But in a particular legal vocabulary, the definition of person can be expanded
    // to include say organizations
    SCollection person = SCollectionImpl.findOrCreate(socialNs + "Person", socialCtx);
    person.addLabel("person", socialCtx);
    person.addGeneralization(agent, socialCtx);
    
    SCollection malePerson = new SCollectionImpl(socialNs + "MalePerson", socialCtx);
    malePerson.addLabel("male person", socialCtx);
    SCollection femalePerson = new SCollectionImpl(socialNs + "FemalePerson", socialCtx);
    femalePerson.addLabel("female person", socialCtx);
    
    malePerson.addGeneralization(person, socialCtx);
    femalePerson.addGeneralization(person, socialCtx);
    Sentence disj = new SentenceImpl(OWL_S.disjointWith, malePerson, femalePerson);
    disj.assertIn(socialCtx);
    
    BinaryPredicate father = new BinaryPredicateImpl(socialNs + "isFatherOf", socialCtx);
    father.addArgIsa(1, malePerson, socialCtx);
    father.addArgIsa(2, person, socialCtx);
    father.addLabel("father", socialCtx);
    
    BinaryPredicate grandFather = new BinaryPredicateImpl(socialNs + "isGrandfatherOf", socialCtx);
    grandFather.addArgIsa(1, malePerson, socialCtx);
    grandFather.addArgIsa(2, person, socialCtx);
    grandFather.addLabel("grandfather", socialCtx);
    
    SObjectImpl.getDataset().commit();
    SObjectImpl.getDataset().end();
  }

  public static void createHumanActivitiesOntology() {
    SObjectImpl.getDataset().begin(ReadWrite.WRITE);

    String socialNs = Constants.TBOX_PART + "SocialVocabulary#";
    Context socialCtx = new ContextImpl(socialNs);

    String eventNs = Constants.TBOX_PART + "event#";
    Context eventCtx = new ContextImpl(eventNs);

    String eatingNs = Constants.TBOX_PART + "FoodConsumption#";
    Context eatingCtx = new ContextImpl(eatingNs);

    String humanActNs = Constants.TBOX_PART + "HumanActivityVocabulary#";
    Context humanActCtx = new ContextImpl(humanActNs);

    humanActCtx.addInheritsFromWithRuleCtx(socialCtx);
    humanActCtx.addInheritsFromWithRuleCtx(eventCtx);
    humanActCtx.addInheritsFromWithRuleCtx(eatingCtx);

    SObjectImpl.getDataset().commit();
    SObjectImpl.getDataset().end();
  }

}
