Code Search for Developers
 
 
  

OWLEntailmentCase.java from Citizen Privacy Service at Krugle


Show OWLEntailmentCase.java syntax highlighted

/**
 * @(#) OWLEntailmentCase.java
 * @author <a href:mailto="rick@rickmurphy.org">Rick Murphy</a>
 * @version 0.1
 * @see <a href="http://www.rickmurphy.org/cps-license.html">Citizen Privacy Service License</a>
 */

package org.rickmurphy.unit;

import java.io.InputStream;
import java.io.BufferedReader;
import java.io.InputStreamReader;

import java.util.Set;

import java.net.URL;
import java.net.URI;

import org.mindswap.pellet.owlapi.Reasoner;

import org.mindswap.pellet.KnowledgeBase;

import org.mindswap.pellet.query.QueryEngine;
import org.mindswap.pellet.query.QueryResults;

import org.semanticweb.owl.model.OWLOntology;

import org.semanticweb.owl.model.helper.OntologyHelper;

import org.mindswap.pellet.jena.OWLReasoner;

import com.hp.hpl.jena.vocabulary.RDFS;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.OntDocManagerVocab;

import com.hp.hpl.jena.shared.PrefixMapping.Factory;
import com.hp.hpl.jena.shared.PrefixMapping;

import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.RDFList;
import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.Literal;

import com.hp.hpl.jena.datatypes.xsd.XSDDatatype;

import com.hp.hpl.jena.util.iterator.ExtendedIterator;

import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntClass;
import com.hp.hpl.jena.ontology.OntProperty;
import com.hp.hpl.jena.ontology.IntersectionClass;
import com.hp.hpl.jena.ontology.Restriction;
import com.hp.hpl.jena.ontology.HasValueRestriction;
import com.hp.hpl.jena.ontology.SomeValuesFromRestriction;
import com.hp.hpl.jena.ontology.Individual;
import com.hp.hpl.jena.ontology.ObjectProperty;
import com.hp.hpl.jena.ontology.DatatypeProperty;
import com.hp.hpl.jena.ontology.DataRange;

import junit.framework.TestCase;

/**
 *
 */

public class OWLEntailmentCase extends TestCase{
  
  /**
   * 
   */
  private static KnowledgeBase kb; 
  private static String privacy = "http://www.osera.gov/owl/2005/12/privacy.owl#";
  private static String brm = "http://www.osera.gov/owl/2004/11/fea/brm.owl";
  private static String feac = "http://www.osera.gov/owl/2004/11/fea/feac.owl#";

  /**
   *  creates the reasoner
   */
  private static OWLReasoner reasoner = new OWLReasoner();
  
  /**
   * creates and configures the ont model with dl reasoning
   */
  private static OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
  private static OntModel lookup = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
  
  /**
   */
  public void setUp() throws Exception{
    
    System.out.println("new test harness");

    reasoner.load("http://www.osera.gov/owl/2005/12//privacy.owl");  
    reasoner.getKB().realize();

    //System.out.println("info: " + reasoner.getKB().getInfo());

    model.setNsPrefix("privacy",privacy);
    model.setNsPrefix("brm",brm);
    model.setNsPrefix("feac",feac);

    lookup.read("http://www.osera.gov/owl/2005/12/privacy.owl");

  }//setUp



  /**
   */
  public void testIntent(){


    // String inp = "";
    // String requestor = "";
    // cooperating agency business agreement and trust agreement
    // routine use = purpose for which it was intended, needs check against stated intent, possibly also implies prior notice & read privvacy disclosure statement, or published intent in federal register, users and purpose
    // statistical disclosure, put mustUnderstand, not release PII, only aggregate
   // if the booleans are there, read them and validate them 
    // intent equals property (routine or statistical)
    // if routine use, do not record interagency disclosures
    // add data purpose algebra
    // collect use maintain disseminate


    // routine disclosure means, from another agency and for the stated purpose of that agency, disclosure source, intra-aency, inter-agency
    // check agency privacy statements and federal register
    // probablistic match

    boolean isRoutineDisclosure = true;

    // creates the granted request and disclosure request 
    OntClass disclosureRequest = model.createClass(privacy + "DisclosureRequest");
    OntClass grantedRequest = model.createClass(privacy + "GrantedRequest");
    
    // creates the boolean typed literal 
    Literal literal = model.createTypedLiteral(privacy+"Present",XSDDatatype.XSDboolean);

    ObjectProperty requestProperty = null;
    OntClass disclosureType = null;

    if(isRoutineDisclosure){
      
      disclosureType = model.createClass(privacy + "RoutineDisclosure");
      requestProperty = model.createObjectProperty(privacy + "routineUse");   
      grantedRequest.addSubClass(disclosureType);	
	
    }else{

      disclosureType = model.createClass(privacy + "StatisticalDisclosure");
      requestProperty = model.createObjectProperty(privacy + "statisticalRequest");   
      grantedRequest.addSubClass(disclosureType);   
      
    }
    
    HasValueRestriction hasValueRestriction = model.createHasValueRestriction(null,requestProperty,model.createResource(literal.getLexicalForm()));       
    IntersectionClass disclosureIntersection = model.createIntersectionClass(disclosureType.getNameSpace()+disclosureType.getLocalName(),model.createList(new RDFNode [] {hasValueRestriction,disclosureRequest}));    
    
    model.write(System.out,"RDF/XML-ABBREV");    
    
    // check the entailment of the model
    assertTrue(reasoner.isEntailed(model));
    
  }//testIntent



//   /**
//    */
//   public void testDocumentEntailment(){

//     // citizen, court, check uri, check uri type. get digital signature, key exchange
    
//      String inp = "http://localhost/court-order.xml";
//     // String inp1 = "judge.judy";
//     // String inp2 = "joe.citizen";

//      // is document a court order ?
//      // is document pursuant to request (by citizen)
//      // establish document structure (standardize)
//      // serialize the document and check for dsig
     
//      boolean isCourtOrder = true;

//     // creates the disclosure target, property restriction and disclosure request 
//      Literal lit = model.createTypedLiteral(inp,XSDDatatype.XSDanyURI);
     
//      // System.out.println("literal is: " + lit);
     
//      String disclosureType = null;
//      SomeValuesFromRestriction someValuesRestriction = null;
//      IntersectionClass disclosureIntersection = null;
//      DatatypeProperty dataTypeProperty = null;
//      OntClass consentedDisclosure = null;

//      OntClass disclosureRequest = model.createClass(privacy + "DisclosureRequest");
//      OntClass grantedRequest = model.createClass(privacy + "GrantedRequest");

//      if(isCourtOrder){

//        disclosureType = privacy + "CourtOrderedRequest";
//        dataTypeProperty = model.createDatatypeProperty(privacy + "hasCourtOrder");
//        someValuesRestriction = model.createSomeValuesFromRestriction(null,dataTypeProperty,model.createResource((XSDDatatype.XSDanyURI).getURI()));       
//        disclosureIntersection = model.createIntersectionClass(disclosureType,model.createList(new RDFNode [] {someValuesRestriction,disclosureRequest}));
       
//        grantedRequest.addSubClass(disclosureIntersection);
       
//      }else{
       
//        consentedDisclosure = model.createClass(privacy + "ConsentedDisclosure");
//        dataTypeProperty = model.createDatatypeProperty(privacy + "pursuantToRequest");

//        someValuesRestriction = model.createSomeValuesFromRestriction(null,dataTypeProperty,model.createResource((XSDDatatype.XSDanyURI).getURI()));       
//        disclosureIntersection = model.createIntersectionClass(null,model.createList(new RDFNode [] {someValuesRestriction,disclosureRequest}));       
       
//        disclosureIntersection.addSuperClass(consentedDisclosure);
//        grantedRequest.addSubClass(consentedDisclosure);   
       
//      }

//      model.write(System.out,"RDF/XML-ABBREV");    
     
//      // check the entailment of the model
//      assertTrue(reasoner.isEntailed(model));
     
//   }//testDocumentEntailment


  /**
   */
//   public void testDisclosureTargetEntailment(){

//     //String inp = privacy + "GovernmentAccountabilityOffice";
//     //String inp = brm + "#BureauoftheCensus";
//     //String inp = brm + "#NationalArchivesandRecordsAdministration";

//     //String inp = privacy + "Senate";
//     //String inp = privacy + "HouseOfRepresentatives";
//     //String inp = privacy + "TransUnion";
//     //String inp = privacy + "Equifax";
//     String inp = privacy + "Experion";

//     HasValueRestriction hasValueRestriction = null;
//     SomeValuesFromRestriction someValuesRestriction = null;
//     IntersectionClass disclosureIntersection = null;
//     String disclosureType = null;

//     // creates the disclosure target, property restriction and disclosure request 
//     Individual disclosureTarget = model.createOntResource(inp).asIndividual();
//     ObjectProperty disclosesTo = model.createObjectProperty(privacy + "disclosesTo");
//     OntClass disclosureRequest = model.createClass(privacy + "DisclosureRequest");
    
//     // looks up and iterates over all the intersection classes from the jena model
//     ExtendedIterator iIt = lookup.listIntersectionClasses();
//     outer: while(iIt.hasNext()){
//       IntersectionClass candidateClass = (IntersectionClass)iIt.next();      

//       // iterate over each operand in the intersection class
//       if(candidateClass.hasOperand(disclosureRequest)){
// 	RDFList rdfList = candidateClass.getOperands();
// 	ExtendedIterator oIt = rdfList.iterator();
	
// 	// gets the disclosure type and creates the disclosure intersection from either the has value or some values restriction 
// 	while(oIt.hasNext()){
// 	  OntClass op = (OntClass)((RDFNode)oIt.next()).as(OntClass.class);
// 	  disclosureType = candidateClass.getNameSpace()+candidateClass.getLocalName();

// 	  // checks the operand for a has value or some values from restriction and matches the disclosure target
// 	  if(op.isRestriction() && ((Restriction)op.as(Restriction.class)).isHasValueRestriction() && ((Restriction)op.as(Restriction.class)).onProperty(disclosesTo) && ((HasValueRestriction)op.as(HasValueRestriction.class)).getHasValue().equals(disclosureTarget)){
	    
// 	    hasValueRestriction = model.createHasValueRestriction(null,disclosesTo,disclosureTarget);
// 	    disclosureIntersection = model.createIntersectionClass(disclosureType,model.createList(new RDFNode [] {hasValueRestriction,disclosureRequest}));

// 	    break outer;
// 	  }else if (op.isRestriction() && ((Restriction)op.as(Restriction.class)).isSomeValuesFromRestriction() && ((Restriction)op.as(Restriction.class)).onProperty(disclosesTo) && ((SomeValuesFromRestriction)op.as(SomeValuesFromRestriction.class)).getSomeValuesFrom().equals(reasoner.getType(disclosureTarget,true))){

// 	    someValuesRestriction = model.createSomeValuesFromRestriction(null,disclosesTo,reasoner.getType(disclosureTarget,true));
// 	    disclosureIntersection = model.createIntersectionClass(disclosureType,model.createList(new RDFNode [] {someValuesRestriction,disclosureRequest}));
  
// 	    break outer;
// 	  }
// 	}
//       }
//     }

//     // adds subclass to model
//     OntClass grantedRequest = model.createClass(privacy + "GrantedRequest");
//     grantedRequest.addSubClass(disclosureIntersection);   

//     model.write(System.out,"RDF/XML-ABBREV");    
    
//     // check the entailment of the model
//     assertTrue(reasoner.isEntailed(model));
    
//   }//testDisclosureTargetEntailment

 }//OWLEntailmentCase




See more files for this project here

Citizen Privacy Service

The Citizen Privacy Service is an asynchronous component using artificial intelligence capabilities including DL decidability and first order logic provenance that provide policy decision and policy enforcement points based on the US Privacy Act of 1974.

Project homepage: http://sourceforge.net/projects/us-privacy
Programming language(s): Java,XML
License: bsd

  KIFGoalCase.java
  OWLEntailmentCase.java
  OWLGoalCase.java