use of org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom in project goci by EBISPOT.
the class DefaultGWASOWLConverter method convertAssociation.
protected void convertAssociation(Association association, OWLOntology ontology, Set<String> issuedWarnings) {
// get the trait association class
OWLClass taClass = getDataFactory().getOWLClass(IRI.create(OntologyConstants.TRAIT_ASSOCIATION_CLASS_IRI));
IRI taIndIRI = getMinter().mint(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI, association);
// create a new trait association instance
OWLNamedIndividual taIndiv = getDataFactory().getOWLNamedIndividual(taIndIRI);
// assert class membership
OWLClassAssertionAxiom classAssertion = getDataFactory().getOWLClassAssertionAxiom(taClass, taIndiv);
getManager().addAxiom(ontology, classAssertion);
// get datatype relations
OWLDataProperty has_p_value = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_P_VALUE_PROPERTY_IRI));
// get annotation relations
OWLAnnotationProperty rdfsLabel = getDataFactory().getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI());
// pvalue but says it was less then 10-6. So if we have no pvalue we just don't add it.
if (association.getPvalueMantissa() != null && association.getPvalueExponent() != null) {
double pval = association.getPvalueMantissa() * Math.pow(10, association.getPvalueExponent());
OWLLiteral pValue = getDataFactory().getOWLLiteral(pval);
// OWLLiteral pValue = getDataFactory().getOWLLiteral(association.getPvalueMantissa()+"e"+association.getPvalueExponent());
OWLDataPropertyAssertionAxiom p_value_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_p_value, taIndiv, pValue);
AddAxiom add_p_value = new AddAxiom(ontology, p_value_relation);
getManager().applyChange(add_p_value);
}
// get the snp instance for this association
OWLNamedIndividual snpIndiv;
String rsId = null;
for (Locus locus : association.getLoci()) {
for (RiskAllele riskAllele : locus.getStrongestRiskAlleles()) {
SingleNucleotidePolymorphism snp = riskAllele.getSnp();
rsId = snp.getRsId();
snpIndiv = getDataFactory().getOWLNamedIndividual(getMinter().mint(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI, snp));
if (snpIndiv == null) {
String warning = "A new SNP with the given RSID only will be created";
if (!issuedWarnings.contains(warning)) {
getLog().warn(warning);
issuedWarnings.add(warning);
}
snpIndiv = getDataFactory().getOWLNamedIndividual(getMinter().mint(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI, "SingleNucleotidePolymorphism", snp.getRsId(), true));
// assert class membership
OWLClass snpClass = getDataFactory().getOWLClass(IRI.create(OntologyConstants.SNP_CLASS_IRI));
OWLClassAssertionAxiom snpClassAssertion = getDataFactory().getOWLClassAssertionAxiom(snpClass, snpIndiv);
getManager().addAxiom(ontology, snpClassAssertion);
// assert rsid relation
OWLDataProperty has_snp_rsid = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_SNP_REFERENCE_ID_PROPERTY_IRI));
OWLLiteral rsid = getDataFactory().getOWLLiteral(snp.getRsId());
OWLDataPropertyAssertionAxiom rsid_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_snp_rsid, snpIndiv, rsid);
AddAxiom add_rsid = new AddAxiom(ontology, rsid_relation);
getManager().applyChange(add_rsid);
// assert label
OWLAnnotationAssertionAxiom snp_label_annotation = getDataFactory().getOWLAnnotationAssertionAxiom(rdfsLabel, snpIndiv.getIRI(), rsid);
AddAxiom add_snp_label = new AddAxiom(ontology, snp_label_annotation);
getManager().applyChange(add_snp_label);
}
// get object properties
OWLObjectProperty has_subject = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.HAS_SUBJECT_IRI));
OWLObjectProperty is_subject_of = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.IS_SUBJECT_OF_IRI));
// assert relations
OWLObjectPropertyAssertionAxiom has_subject_snp_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(has_subject, taIndiv, snpIndiv);
AddAxiom add_has_subject_snp = new AddAxiom(ontology, has_subject_snp_relation);
getManager().applyChange(add_has_subject_snp);
OWLObjectPropertyAssertionAxiom is_subject_of_snp_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(is_subject_of, snpIndiv, taIndiv);
AddAxiom add_is_subject_of_snp = new AddAxiom(ontology, is_subject_of_snp_relation);
getManager().applyChange(add_is_subject_of_snp);
}
// get the EFO class for the trait
for (EfoTrait efoTrait : association.getEfoTraits()) {
OWLClass traitClass;
traitClass = getDataFactory().getOWLClass(IRI.create(efoTrait.getUri()));
if (traitClass == null) {
String warning = "This trait will be mapped to Experimental Factor";
if (!issuedWarnings.contains(warning)) {
getLog().warn(warning);
issuedWarnings.add(warning);
}
traitClass = getDataFactory().getOWLClass(IRI.create(OntologyConstants.EXPERIMENTAL_FACTOR_CLASS_IRI));
}
// create a new trait instance (puns the class)
IRI traitIRI = traitClass.getIRI();
OWLNamedIndividual traitIndiv = getDataFactory().getOWLNamedIndividual(traitIRI);
if (ontology.containsIndividualInSignature(traitIRI)) {
getLog().trace("Trait individual '" + traitIRI.toString() + "' (type: " + traitClass + ") already exists");
} else {
getLog().trace("Creating trait individual '" + traitIRI.toString() + "' (type: " + traitClass + ")");
}
// and also add the gwas label to the individual so we don't lose curated data
OWLDataProperty has_gwas_trait_name = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_GWAS_TRAIT_NAME_PROPERTY_IRI));
OWLLiteral gwasTrait = getDataFactory().getOWLLiteral(association.getStudy().getDiseaseTrait().getTrait());
OWLDataPropertyAssertionAxiom gwas_trait_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_gwas_trait_name, taIndiv, gwasTrait);
AddAxiom add_gwas_trait_name = new AddAxiom(ontology, gwas_trait_relation);
getManager().applyChange(add_gwas_trait_name);
// assert class membership
OWLClassAssertionAxiom traitClassAssertion = getDataFactory().getOWLClassAssertionAxiom(traitClass, traitIndiv);
getManager().addAxiom(ontology, traitClassAssertion);
// get object properties
OWLObjectProperty has_object = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.HAS_OBJECT_IRI));
OWLObjectProperty is_object_of = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.IS_OBJECT_OF_IRI));
// assert relations
OWLObjectPropertyAssertionAxiom has_object_trait_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(has_object, taIndiv, traitIndiv);
AddAxiom add_has_object_trait = new AddAxiom(ontology, has_object_trait_relation);
getManager().applyChange(add_has_object_trait);
OWLObjectPropertyAssertionAxiom is_object_of_trait_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(is_object_of, traitIndiv, taIndiv);
AddAxiom add_is_object_of_trait = new AddAxiom(ontology, is_object_of_trait_relation);
getManager().applyChange(add_is_object_of_trait);
}
// finally, assert label for this association
OWLLiteral label = getDataFactory().getOWLLiteral("Association between " + rsId + " and " + association.getStudy().getDiseaseTrait().getTrait());
OWLAnnotationAssertionAxiom label_annotation = getDataFactory().getOWLAnnotationAssertionAxiom(rdfsLabel, taIndiv.getIRI(), label);
AddAxiom add_band_label = new AddAxiom(ontology, label_annotation);
getManager().applyChange(add_band_label);
}
}
use of org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom in project goci by EBISPOT.
the class DefaultGWASOWLConverter method convertSNP.
protected void convertSNP(SingleNucleotidePolymorphism snp, OWLOntology ontology) {
log.debug("converting snp: " + snp.getId() + ", rsid: " + snp.getRsId());
// get the snp class
OWLClass snpClass = getDataFactory().getOWLClass(IRI.create(OntologyConstants.SNP_CLASS_IRI));
// create a new snp instance
OWLNamedIndividual snpIndiv = getDataFactory().getOWLNamedIndividual(getMinter().mint(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI, snp));
// assert class membership
OWLClassAssertionAxiom classAssertion = getDataFactory().getOWLClassAssertionAxiom(snpClass, snpIndiv);
getManager().addAxiom(ontology, classAssertion);
// add datatype properties...
// get datatype relations
OWLDataProperty has_snp_rsid = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_SNP_REFERENCE_ID_PROPERTY_IRI));
OWLDataProperty has_bp_pos = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_BP_POSITION_PROPERTY_IRI));
// get annotation relations
OWLAnnotationProperty rdfsLabel = getDataFactory().getOWLAnnotationProperty(OWLRDFVocabulary.RDFS_LABEL.getIRI());
// assert rsid relation
OWLLiteral rsid = getDataFactory().getOWLLiteral(snp.getRsId());
OWLDataPropertyAssertionAxiom rsid_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_snp_rsid, snpIndiv, rsid);
AddAxiom add_rsid = new AddAxiom(ontology, rsid_relation);
getManager().applyChange(add_rsid);
// assert bp_pos relation
if (snp.getLocations() != null) {
for (Location snpLocation : snp.getLocations()) {
if (snpLocation.getChromosomePosition() != null) {
OWLLiteral bp_pos = // getDataFactory().getOWLLiteral(snpLocation.getChromosomePosition(), OWL2Datatype.XSD_INT);
getDataFactory().getOWLLiteral(snpLocation.getChromosomePosition());
OWLDataPropertyAssertionAxiom bp_pos_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_bp_pos, snpIndiv, bp_pos);
AddAxiom add_bp_pos = new AddAxiom(ontology, bp_pos_relation);
getManager().applyChange(add_bp_pos);
}
}
} else {
getLog().debug("No SNP location available for SNP " + rsid);
}
// assert label
OWLAnnotationAssertionAxiom snp_label_annotation = getDataFactory().getOWLAnnotationAssertionAxiom(rdfsLabel, snpIndiv.getIRI(), rsid);
AddAxiom add_snp_label = new AddAxiom(ontology, snp_label_annotation);
getManager().applyChange(add_snp_label);
// get the band class
OWLClass bandClass = getDataFactory().getOWLClass(IRI.create(OntologyConstants.CYTOGENIC_REGION_CLASS_IRI));
// get datatype relations
OWLDataProperty has_name = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_NAME_PROPERTY_IRI));
// get object relations
OWLObjectProperty located_in = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.LOCATED_IN_PROPERTY_IRI));
OWLObjectProperty location_of = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.LOCATION_OF_PROPERTY_IRI));
// get datatype relations
OWLDataProperty has_chr_name = getDataFactory().getOWLDataProperty(IRI.create(OntologyConstants.HAS_NAME_PROPERTY_IRI));
// get object properties
OWLObjectProperty has_part = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.HAS_PART_PROPERTY_IRI));
OWLObjectProperty part_of = getDataFactory().getOWLObjectProperty(IRI.create(OntologyConstants.PART_OF_PROPERTY_IRI));
for (Location location : snp.getLocations()) {
Region region = location.getRegion();
if (region.getName() != null) {
// create a new band individual
OWLNamedIndividual bandIndiv = getDataFactory().getOWLNamedIndividual(getMinter().mint(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI, "CytogeneticRegion", region.getName()));
// assert class membership
OWLClassAssertionAxiom bandClassAssertion = getDataFactory().getOWLClassAssertionAxiom(bandClass, bandIndiv);
getManager().addAxiom(ontology, bandClassAssertion);
// assert name relation
OWLLiteral name = getDataFactory().getOWLLiteral(region.getName());
OWLDataPropertyAssertionAxiom name_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_name, bandIndiv, name);
AddAxiom add_name = new AddAxiom(ontology, name_relation);
getManager().applyChange(add_name);
// assert label
OWLAnnotationAssertionAxiom band_label_annotation = getDataFactory().getOWLAnnotationAssertionAxiom(rdfsLabel, bandIndiv.getIRI(), name);
AddAxiom add_band_label = new AddAxiom(ontology, band_label_annotation);
getManager().applyChange(add_band_label);
// assert located_in relation
OWLObjectPropertyAssertionAxiom located_in_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(located_in, snpIndiv, bandIndiv);
AddAxiom add_located_in = new AddAxiom(ontology, located_in_relation);
getManager().applyChange(add_located_in);
// assert location_of relation
OWLObjectPropertyAssertionAxiom location_of_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(location_of, bandIndiv, snpIndiv);
AddAxiom add_location_of = new AddAxiom(ontology, location_of_relation);
getManager().applyChange(add_location_of);
// get the appropriate chromosome class given the chromosome name
OWLClass chrClass = getDataFactory().getOWLClass(IRI.create(OntologyConstants.CHROMOSOME_CLASS_IRI));
// create a new chromosome individual
// If a snp has a chromosome name, create the chromosome individual if it doesn't have one (ex : the snp is
// no mapped any more) then just don't create it.
String chromName = location.getChromosomeName();
if (chromName != null) {
OWLNamedIndividual chrIndiv = getDataFactory().getOWLNamedIndividual(getMinter().mint(OntologyConstants.GWAS_ONTOLOGY_BASE_IRI, "Chromosome", chromName));
OWLClassAssertionAxiom chrClassAssertion = getDataFactory().getOWLClassAssertionAxiom(chrClass, chrIndiv);
getManager().addAxiom(ontology, chrClassAssertion);
// assert chr_name relation
OWLLiteral chr_name = getDataFactory().getOWLLiteral(chromName);
OWLDataPropertyAssertionAxiom chr_name_relation = getDataFactory().getOWLDataPropertyAssertionAxiom(has_chr_name, chrIndiv, chr_name);
AddAxiom add_chr_name = new AddAxiom(ontology, chr_name_relation);
getManager().applyChange(add_chr_name);
// assert label
OWLLiteral chr_label = getDataFactory().getOWLLiteral("Chromosome " + chromName);
OWLAnnotationAssertionAxiom chr_label_annotation = getDataFactory().getOWLAnnotationAssertionAxiom(rdfsLabel, chrIndiv.getIRI(), chr_label);
AddAxiom add_chr_label = new AddAxiom(ontology, chr_label_annotation);
getManager().applyChange(add_chr_label);
// assert has_part relation
OWLObjectPropertyAssertionAxiom has_part_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(has_part, chrIndiv, bandIndiv);
AddAxiom add_has_part = new AddAxiom(ontology, has_part_relation);
getManager().applyChange(add_has_part);
// assert part_of relation
OWLObjectPropertyAssertionAxiom part_of_relation = getDataFactory().getOWLObjectPropertyAssertionAxiom(part_of, bandIndiv, chrIndiv);
AddAxiom add_part_of = new AddAxiom(ontology, part_of_relation);
getManager().applyChange(add_part_of);
}
} else {
getLog().trace("No known region for location on chromosomse " + location.getChromosomeName());
}
}
}
use of org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom in project stanbol by apache.
the class RegistryManagerImpl method createModel.
@Override
public Set<Registry> createModel(Set<OWLOntology> registryOntologies) {
Set<Registry> results = new HashSet<Registry>();
// Reset population
population.clear();
// Build the transitive imports closure of the union.
Set<OWLOntology> closure = new HashSet<OWLOntology>();
for (OWLOntology rego : registryOntologies) closure.addAll(rego.getOWLOntologyManager().getImportsClosure(rego));
/*
* For each value in this map, index 0 is the score of the library class, while 1 is the score of the
* ontology class.
*/
final Map<IRI, int[]> candidateTypes = new HashMap<IRI, int[]>();
/*
* Scans class assertions and object property values and tries to determine the type of each
* individual it finds.
*/
OWLAxiomVisitor scanner = new OWLAxiomVisitorAdapter() {
/*
* For a given identifier, returns the array of integers whose value determine the likelihood if
* the corresponding entity being a library or an ontology. If no such array exists, it is
* created.
*/
private int[] checkScores(IRI key) {
int[] scores;
if (candidateTypes.containsKey(key))
scores = candidateTypes.get(key);
else {
scores = new int[] { 0, 0 };
candidateTypes.put(key, scores);
}
return scores;
}
@Override
public void visit(OWLAnnotationAssertionAxiom axiom) {
/*
* Works like object property assertions, in case hasOntology and isOntologyOf are not
* detected to be object properties (e.g. due to a failure to load codolight or the registry
* metamodel).
*/
OWLAnnotationProperty prop = axiom.getProperty();
if (hasOntologyAnn.equals(prop)) {
IRI iri;
// The axiom subject gets a +1 in its library score.
OWLObject ind = axiom.getSubject();
if (ind instanceof IRI) {
iri = (IRI) ind;
checkScores(iri)[0]++;
}
// The axiom object gets a +1 in its ontology score.
ind = axiom.getValue();
if (ind instanceof IRI) {
iri = (IRI) ind;
checkScores(iri)[1]++;
}
} else if (isOntologyOfAnn.equals(prop)) {
IRI iri;
// The axiom subject gets a +1 in its ontology score.
OWLObject ind = axiom.getSubject();
if (ind instanceof IRI) {
iri = (IRI) ind;
checkScores(iri)[1]++;
}
// The axiom object gets a +1 in its library score.
ind = axiom.getValue();
if (ind instanceof IRI) {
iri = (IRI) ind;
checkScores(iri)[0]++;
}
}
}
@Override
public void visit(OWLClassAssertionAxiom axiom) {
OWLIndividual ind = axiom.getIndividual();
// Do not accept anonymous registry items.
if (ind.isAnonymous())
return;
IRI iri = ind.asOWLNamedIndividual().getIRI();
int[] scores = checkScores(iri);
OWLClassExpression type = axiom.getClassExpression();
// If the type is stated to be a library, increase its library score.
if (cRegistryLibrary.equals(type)) {
scores[0]++;
} else // If the type is stated to be an ontology, increase its ontology score.
if (cOntology.equals(type)) {
scores[1]++;
}
}
@Override
public void visit(OWLObjectPropertyAssertionAxiom axiom) {
OWLObjectPropertyExpression prop = axiom.getProperty();
if (hasOntology.equals(prop)) {
IRI iri;
// The axiom subject gets a +1 in its library score.
OWLIndividual ind = axiom.getSubject();
if (!ind.isAnonymous()) {
iri = ind.asOWLNamedIndividual().getIRI();
checkScores(iri)[0]++;
}
// The axiom object gets a +1 in its ontology score.
ind = axiom.getObject();
if (!ind.isAnonymous()) {
iri = ind.asOWLNamedIndividual().getIRI();
checkScores(iri)[1]++;
}
} else if (isOntologyOf.equals(prop)) {
IRI iri;
// The axiom subject gets a +1 in its ontology score.
OWLIndividual ind = axiom.getSubject();
if (!ind.isAnonymous()) {
iri = ind.asOWLNamedIndividual().getIRI();
checkScores(iri)[1]++;
}
// The axiom object gets a +1 in its library score.
ind = axiom.getObject();
if (!ind.isAnonymous()) {
iri = ind.asOWLNamedIndividual().getIRI();
checkScores(iri)[0]++;
}
}
}
};
// First pass to determine the types.
for (OWLOntology o : closure) for (OWLAxiom ax : o.getAxioms()) ax.accept(scanner);
// Then populate on the registry
OWLDataFactory df = OWLManager.getOWLDataFactory();
for (IRI iri : candidateTypes.keySet()) {
int[] scores = candidateTypes.get(iri);
if (scores != null && (scores[0] > 0 || scores[1] > 0)) {
if (scores[0] > 0 && scores[1] == 0)
population.put(iri, riFactory.createLibrary(df.getOWLNamedIndividual(iri)));
else if (scores[0] == 0 && scores[1] > 0)
population.put(iri, riFactory.createRegistryOntology(df.getOWLNamedIndividual(iri)));
}
// else log.warn("Unable to determine type for registry item {}", iri);
}
for (OWLOntology oReg : registryOntologies) {
try {
results.add(populateRegistry(oReg));
} catch (RegistryContentException e) {
log.error("An error occurred while populating an ontology registry.", e);
}
}
return results;
}
use of org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom in project stanbol by apache.
the class RegistryManagerImpl method populateOntology.
protected RegistryOntology populateOntology(OWLNamedObject ind, Set<OWLOntology> registries) throws RegistryContentException {
IRI ontId = ind.getIRI();
RegistryItem ront = null;
if (population.containsKey(ontId)) {
// We are not allowing multityping either.
ront = population.get(ontId);
if (!(ront instanceof RegistryOntology))
throw new RegistryContentException("Inconsistent multityping: for item " + ontId + " : {" + RegistryOntology.class + ", " + ront.getClass() + "}");
} else {
ront = riFactory.createRegistryOntology(ind);
try {
population.put(ront.getIRI(), ront);
} catch (Exception e) {
log.error("Invalid identifier for library item " + ront, e);
return null;
}
}
// EXIT nodes.
Set<OWLNamedObject> libs = new HashSet<OWLNamedObject>();
OWLDataFactory df = OWLManager.getOWLDataFactory();
for (OWLOntology o : registries) {
if (ind instanceof OWLIndividual) {
// Get usages of isOntologyOf as an object property
for (OWLIndividual value : ((OWLIndividual) ind).getObjectPropertyValues(isOntologyOf, o)) if (value.isNamed())
libs.add(value.asOWLNamedIndividual());
// Get usages of isOntologyOf as an annotation property
for (OWLAnnotationAssertionAxiom ann : o.getAnnotationAssertionAxioms(ind.getIRI())) if (isOntologyOfAnn.equals(ann.getProperty())) {
OWLAnnotationValue value = ann.getValue();
if (value instanceof OWLNamedObject)
libs.add((OWLNamedObject) value);
else if (value instanceof IRI)
libs.add(df.getOWLNamedIndividual((IRI) value));
}
}
}
for (OWLNamedObject ilib : libs) {
IRI parentId = ilib.getIRI();
// If some populate*() method has created it, it will be there.
RegistryItem rlib = population.get(parentId);
// Otherwise populating it will also put it in population.
if (rlib == null)
rlib = populateLibrary(ilib, registries);
ront.addParent(rlib);
if (ontologyIndex.get(ontId) == null)
ontologyIndex.put(ontId, new HashSet<IRI>());
ontologyIndex.get(ontId).add(parentId);
}
return (RegistryOntology) ront;
}
use of org.semanticweb.owlapi.model.OWLAnnotationAssertionAxiom in project stanbol by apache.
the class ConversionTester method testAxiomOwlToJenaResource.
public void testAxiomOwlToJenaResource() {
JenaToOwlConvert j2o = new JenaToOwlConvert();
OWLOntologyManager mgr = OWLManager.createOWLOntologyManager();
OWLOntology ont = null;
try {
ont = mgr.createOntology();
} catch (OWLOntologyCreationException e) {
e.printStackTrace();
fail("Can not create ontology");
}
OWLDataFactory factory = mgr.getOWLDataFactory();
StmtIterator resource = null;
OWLClass cls = factory.getOWLClass(IRI.create(CLAZZ));
OWLDataProperty dp = factory.getOWLDataProperty(IRI.create(DP));
OWLObjectProperty op = factory.getOWLObjectProperty(IRI.create(OP));
OWLAnnotationProperty oa = factory.getOWLAnnotationProperty(IRI.create(label));
OWLAnnotation oav = factory.getOWLAnnotation(oa, factory.getOWLStringLiteral(clazzlabel, "en"));
OWLDatatype dt = factory.getOWLDatatype(IRI.create(DATATYPE));
OWLNamedIndividual sub = factory.getOWLNamedIndividual(IRI.create(SUBJECT));
OWLNamedIndividual obj = factory.getOWLNamedIndividual(IRI.create(OBJECT));
OWLLiteral literal1 = factory.getOWLTypedLiteral(VALUE, dt);
// Classe
OWLDeclarationAxiom daxiomcls = factory.getOWLDeclarationAxiom(cls);
// obj prop
OWLDeclarationAxiom daxiomop = factory.getOWLDeclarationAxiom(op);
// data prop
OWLDeclarationAxiom daxiomdp = factory.getOWLDeclarationAxiom(dp);
// subject
OWLDeclarationAxiom daxiomsub = factory.getOWLDeclarationAxiom(sub);
// object
OWLDeclarationAxiom daxiomobj = factory.getOWLDeclarationAxiom(obj);
// Istanza
OWLClassAssertionAxiom axiomsub = factory.getOWLClassAssertionAxiom(cls, sub);
// Istanza
OWLClassAssertionAxiom axiomobj = factory.getOWLClassAssertionAxiom(cls, obj);
// Obj
OWLObjectPropertyAssertionAxiom axiomop = factory.getOWLObjectPropertyAssertionAxiom(op, sub, obj);
// prop
// tra
// individui
OWLDataPropertyAssertionAxiom axiomvalue = factory.getOWLDataPropertyAssertionAxiom(dp, obj, // Dataprop all'istanza;
literal1);
// Annotazione
OWLAnnotationAssertionAxiom axioman = factory.getOWLAnnotationAssertionAxiom(cls.getIRI(), oav);
mgr.addAxiom(ont, daxiomcls);
mgr.addAxiom(ont, daxiomop);
mgr.addAxiom(ont, daxiomdp);
mgr.addAxiom(ont, daxiomsub);
mgr.addAxiom(ont, daxiomobj);
mgr.addAxiom(ont, axiomsub);
mgr.addAxiom(ont, axiomobj);
mgr.addAxiom(ont, axiomop);
mgr.addAxiom(ont, axiomvalue);
mgr.addAxiom(ont, axioman);
Set<OWLAxiom> setaxiom = ont.getAxioms();
try {
resource = j2o.AxiomOwlToJenaResource(setaxiom, RDFXML);
if (resource == null) {
fail("Some errors occur");
} else {
String statment = "[http://www.w3.org/2000/01/rdf-schema#label, http://www.w3.org/2000/01/rdf-schema#range, http://www.w3.org/2000/01/rdf-schema#Literal] " + "[http://example.org/dummy#hasAge, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#DatatypeProperty] " + "[http://example.org/dummy#Linus, http://example.org/dummy#hasAge, \"8\"^^http://www.w3.org/2001/XMLSchema#int] " + "[http://example.org/dummy#Linus, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://example.org/dummy#Peanut] " + "[http://example.org/dummy#hasSibling, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#ObjectProperty] " + "[http://example.org/dummy#Lucy, http://example.org/dummy#hasSibling, http://example.org/dummy#Linus] " + "[http://example.org/dummy#Lucy, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://example.org/dummy#Peanut] " + "[http://www.w3.org/2000/01/rdf-schema#label, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#AnnotationProperty] " + "[http://example.org/dummy#Peanut, http://www.w3.org/2000/01/rdf-schema#label, \"Peanut\"@en] " + "[http://example.org/dummy#Peanut, http://www.w3.org/1999/02/22-rdf-syntax-ns#type, http://www.w3.org/2002/07/owl#Class]";
int size = setaxiom.size();
int count = 0;
while (resource.hasNext()) {
Statement stm = resource.nextStatement();
Resource jsubj = stm.getSubject();
if (jsubj.getURI().equals(OP.toString()) || jsubj.getURI().equals(DP.toString()) || jsubj.getURI().equals(CLAZZ.toString()) || jsubj.getURI().equals(OBJECT.toString()) || jsubj.getURI().equals(SUBJECT.toString()) || jsubj.getURI().equals(label.toString()))
if (statment.contains(stm.toString()))
count++;
}
assertEquals(size, count);
}
} catch (Exception e) {
e.printStackTrace();
fail("Exception caugth");
} finally {
assertNotNull(resource);
}
}
Aggregations