Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Person - Abstract class for creating a person
- *
- * @author NeoSniperkiller
- */
- public class Person extends AmigoPhysicalEntity {
- private final String personURI = ThesisOntologyTools.PERSON_URI + "Person";
- private final String isLocationConfirmedURI = ThesisOntologyTools.PERSON_URI + "isLocationConfirmed";
- private final String hasCurrentRoleURI = ThesisOntologyTools.PERSON_URI + "hasCurrentRole";
- private final String hasRoleURI = ThesisOntologyTools.PERSON_URI + "hasRole";
- private final String hasCurrentTaskURI = ThesisOntologyTools.TASK_URI + "hasCurrentTask";
- private final String hasToDoTaskURI = ThesisOntologyTools.TASK_URI + "hasToDoTask";
- private final String hasLocationURI = ThesisOntologyTools.CONTEXT_URI + "hasLocation";
- // local variables
- protected Role currentRole;
- protected Role role;
- protected Task currentTask;
- protected List<Task> todoTasks;
- protected boolean locationConfirmed;
- protected AmigoRoom currentLocation;
- /**
- * Empty constructor - DO NOT USE this constructor for anything else than instantiating a dummy object of this class
- *
- * @deprecated Only use this constructor in the process of converting a OWLIndividual
- */
- public Person() {
- super();
- }
- /**
- * Default constructor
- *
- * @param personID String representation of a person id
- * @param personStatus Status of the person
- * @param currentRole Role of the person
- */
- public Person(ID personID, PersonStatus personStatus, Role currentRole) {
- super(personID, personStatus);
- this.currentRole = currentRole;
- }
- /**
- * @return the currentRole
- */
- public Role getCurrentRole() {
- return currentRole;
- }
- /**
- * @param currentRole the currentRole to set
- */
- public void setCurrentRole(Role currentRole) {
- this.currentRole = currentRole;
- }
- /**
- * @return the role
- */
- public Role getRole() {
- return role;
- }
- /**
- * @param role the role to set
- */
- public void setRole(Role role) {
- this.role = role;
- }
- /**
- * @return the currentTask
- */
- public Task getCurrentTask() {
- return currentTask;
- }
- /**
- * @param currentTask the currentTask to set
- */
- public void setCurrentTask(Task currentTask) {
- this.currentTask = currentTask;
- }
- /**
- * @return the todoTasks
- */
- public List<Task> getTodoTasks() {
- return todoTasks;
- }
- /**
- * @param todoTasks the todoTasks to set
- */
- public void setTodoTasks(List<Task> todoTasks) {
- this.todoTasks = todoTasks;
- }
- /**
- * @return the locationConfirmed
- */
- public boolean isLocationConfirmed() {
- return locationConfirmed;
- }
- /**
- * @param locationConfirmed the locationConfirmed to set
- */
- public void setLocationConfirmed(boolean locationConfirmed) {
- this.locationConfirmed = locationConfirmed;
- }
- /**
- * @return the currentLocation
- */
- public AmigoRoom getCurrentLocation() {
- return currentLocation;
- }
- /**
- * @param currentLocation the currentLocation to set
- */
- public void setCurrentLocation(AmigoRoom currentLocation) {
- this.currentLocation = currentLocation;
- }
- @Override
- public OWLIndividual convertToReasoningIndividual(OWLOntologyManager ontologyManager, OWLDataFactory dataFactory, OWLOntology ontology, OWLIndividual parentIndividual) {
- OWLIndividual person = parentIndividual;
- if(parentIndividual == null) {
- OWLClass personClass = dataFactory.getOWLClass(IRI.create(personURI));
- person = dataFactory.getOWLNamedIndividual(IRI.create(ThesisOntologyTools.PERSON_URI + "Person_" + super.id));
- OWLAxiom axiom = dataFactory.getOWLClassAssertionAxiom(personClass, person);
- ontologyManager.addAxiom(ontology, axiom);
- }
- // data properties
- // ===============
- // - locationConfirmed
- OWLDataProperty isLocationConfirmed = dataFactory.getOWLDataProperty(IRI.create(isLocationConfirmedURI));
- OWLDataPropertyAssertionAxiom pidAssertion = dataFactory.getOWLDataPropertyAssertionAxiom(isLocationConfirmed, person, locationConfirmed);
- ontologyManager.addAxiom(ontology, pidAssertion);
- // object properties
- // =================
- // - hasCurrentRole
- if(currentRole != null) {
- OWLIndividual currentRoleIndividual = currentRole.convertToReasoningIndividual(ontologyManager, dataFactory, ontology, person);
- OWLObjectProperty hasCurrentRole = dataFactory.getOWLObjectProperty(IRI.create(hasCurrentRoleURI));
- OWLObjectPropertyAssertionAxiom assertion = dataFactory.getOWLObjectPropertyAssertionAxiom(hasCurrentRole, person, currentRoleIndividual);
- ontologyManager.addAxiom(ontology, assertion);
- }
- // - hasRole
- if(role != null) {
- OWLIndividual roleIndividual = role.convertToReasoningIndividual(ontologyManager, dataFactory, ontology, person);
- OWLObjectProperty hasRole = dataFactory.getOWLObjectProperty(IRI.create(hasRoleURI));
- OWLObjectPropertyAssertionAxiom assertion = dataFactory.getOWLObjectPropertyAssertionAxiom(hasRole, person, roleIndividual);
- ontologyManager.addAxiom(ontology, assertion);
- }
- // - hasCurrentTask
- if(currentTask != null) {
- OWLIndividual currentTaskIndividual = currentTask.convertToReasoningIndividual(ontologyManager, dataFactory, ontology, person);
- OWLObjectProperty hasCurrentTask = dataFactory.getOWLObjectProperty(IRI.create(hasCurrentTaskURI));
- OWLObjectPropertyAssertionAxiom assertion = dataFactory.getOWLObjectPropertyAssertionAxiom(hasCurrentTask, person, currentTaskIndividual);
- ontologyManager.addAxiom(ontology, assertion);
- }
- // - hasToDoTask
- if(todoTasks != null) {
- for(Task todoTask : todoTasks) {
- OWLIndividual todoTaskIndividual = todoTask.convertToReasoningIndividual(ontologyManager, dataFactory, ontology, person);
- OWLObjectProperty hasToDoTask = dataFactory.getOWLObjectProperty(IRI.create(hasToDoTaskURI));
- OWLObjectPropertyAssertionAxiom assertion = dataFactory.getOWLObjectPropertyAssertionAxiom(hasToDoTask, person, todoTaskIndividual);
- ontologyManager.addAxiom(ontology, assertion);
- }
- }
- // - hasLocation
- if(currentLocation != null) {
- OWLIndividual locationIndividual = currentLocation.convertToReasoningIndividual(ontologyManager, dataFactory, ontology, person);
- OWLObjectProperty hasLocation = dataFactory.getOWLObjectProperty(IRI.create(hasLocationURI));
- OWLObjectPropertyAssertionAxiom assertion = dataFactory.getOWLObjectPropertyAssertionAxiom(hasLocation, person, locationIndividual);
- ontologyManager.addAxiom(ontology, assertion);
- }
- return super.convertToReasoningIndividual(ontologyManager, dataFactory, ontology, person);
- }
- @Override
- public void convertFromReasoningIndividual(OWLNamedIndividual reasoningIndividual, OWLDataFactory dataFactory, OWLReasoner reasoner) {
- // extract properties from this class
- // - data properties
- // -- locationConfirmed
- OWLDataProperty dataProperty = dataFactory.getOWLDataProperty(IRI.create(isLocationConfirmedURI));
- Set<OWLLiteral> returnLiterals = reasoner.getDataPropertyValues(reasoningIndividual, dataProperty);
- this.locationConfirmed = returnLiterals.iterator().next().parseBoolean();
- // - object properties
- // -- currentRole
- OWLObjectProperty objectProperty = dataFactory.getOWLObjectProperty(IRI.create(hasCurrentRoleURI));
- Set<OWLNamedIndividual> returnObjects = reasoner.getObjectPropertyValues(reasoningIndividual, objectProperty).getFlattened();
- if(returnObjects.size() > 0) {
- this.currentRole = Role.retrieveCorrespondingLocalObject(returnObjects.iterator().next(), dataFactory, reasoner);
- }
- // -- role
- objectProperty = dataFactory.getOWLObjectProperty(IRI.create(hasRoleURI));
- returnObjects = reasoner.getObjectPropertyValues(reasoningIndividual, objectProperty).getFlattened();
- if(returnObjects.size() > 0) {
- this.role = Role.retrieveCorrespondingLocalObject(returnObjects.iterator().next(), dataFactory, reasoner);
- }
- // -- currentTask
- objectProperty = dataFactory.getOWLObjectProperty(IRI.create(hasCurrentTaskURI));
- returnObjects = reasoner.getObjectPropertyValues(reasoningIndividual, objectProperty).getFlattened();
- if(returnObjects.size() > 0) {
- this.currentTask = Task.retrieveCorrespondingLocalObject(returnObjects.iterator().next(), dataFactory, reasoner);
- }
- // -- todoTasks
- objectProperty = dataFactory.getOWLObjectProperty(IRI.create(hasToDoTaskURI));
- returnObjects = reasoner.getObjectPropertyValues(reasoningIndividual, objectProperty).getFlattened();
- if(returnObjects.size() > 0) {
- this.todoTasks = new ArrayList<Task>();
- for(OWLNamedIndividual oi : returnObjects) {
- this.todoTasks.add(Task.retrieveCorrespondingLocalObject(oi, dataFactory, reasoner));
- }
- }
- // -- hasLocation
- objectProperty = dataFactory.getOWLObjectProperty(IRI.create(hasCurrentTaskURI));
- returnObjects = reasoner.getObjectPropertyValues(reasoningIndividual, objectProperty).getFlattened();
- if(returnObjects.size() > 0) {
- this.currentTask = Task.retrieveCorrespondingLocalObject(returnObjects.iterator().next(), dataFactory, reasoner);
- }
- // continue extracting in the superclass
- super.convertFromReasoningIndividual(reasoningIndividual, dataFactory, reasoner);
- }
- public static Person retrieveCorrespondingLocalObject(OWLNamedIndividual reasoningIndividual, OWLDataFactory dataFactory, OWLReasoner reasoner) {
- String oiURI = reasoningIndividual.getIRI().getFragment();
- Person e = null;
- if(oiURI.contains("Man")) {
- e = new Man();
- }
- if(oiURI.contains("Woman")) {
- e = new Woman();
- }
- if(oiURI.contains("StressedPerson")) {
- e = new StressedPerson();
- }
- if(oiURI.contains("Person")) {
- e = new Person();
- }
- if(e != null) {
- e.convertFromReasoningIndividual(reasoningIndividual, dataFactory, reasoner);
- }
- return e;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement