Skip to content

Commit

Permalink
Merge pull request #626 from dgarijo/develop
Browse files Browse the repository at this point in the history
Fix #609, Fix #588 Fix #530
  • Loading branch information
dgarijo authored Aug 27, 2023
2 parents 6859199 + 13a735d commit 2ff38f5
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 10 deletions.
26 changes: 25 additions & 1 deletion src/main/java/widoco/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,31 @@ public void loadPropertiesFromOntology(OWLOntology o) {
});
}
this.mainOntologyMetadata.setThisVersion(versionUri);
// process ontology annotations
o.annotations().forEach(a -> completeOntologyMetadata(a,o));
// in some cases, properties and data properties extend annotation properties, so we need to process them
// separately. In this case we go through all axioms and look for any props that have the own ontology as subject
for (OWLAxiom axiom : o.getAxioms()) {
String subject = "", predicate ="", object ="";
if (axiom instanceof OWLDataPropertyAssertionAxiom) {
OWLDataPropertyAssertionAxiom dataPropertyAssertionAxiom = (OWLDataPropertyAssertionAxiom) axiom;
subject = dataPropertyAssertionAxiom.getSubject().toStringID();
predicate = dataPropertyAssertionAxiom.getProperty().asOWLDataProperty().toStringID();
object = dataPropertyAssertionAxiom.getObject().getLiteral();
} else if (axiom instanceof OWLObjectPropertyAssertionAxiom) {
OWLObjectPropertyAssertionAxiom objectPropertyAssertionAxiom = (OWLObjectPropertyAssertionAxiom) axiom;
subject = objectPropertyAssertionAxiom.getSubject().toStringID();
predicate = objectPropertyAssertionAxiom.getProperty().asOWLObjectProperty().toStringID();
object = objectPropertyAssertionAxiom.getObject().toStringID();
}
if (subject.equals(uri)){
OWLDataFactory dataFactory = this.mainOntologyMetadata.getOWLAPIOntologyManager().getOWLDataFactory();
OWLAnnotationProperty pAux = dataFactory.getOWLAnnotationProperty(IRI.create(predicate));
OWLAnnotationValue oAux = dataFactory.getOWLLiteral(object);
completeOntologyMetadata(dataFactory.getOWLAnnotation(pAux,oAux),o);
}
}

if (isUseLicensius()) {
String licName;
String lic = GetLicense.getFirstLicenseFound(mainOntologyMetadata.getNamespaceURI());
Expand Down Expand Up @@ -513,7 +537,7 @@ private void completeOntologyMetadata(OWLAnnotation a, OWLOntology o) {
String propertyName = a.getProperty().getIRI().getIRIString();
String value;
String valueLanguage;
// System.out.println(propertyName);
//System.out.println(propertyName);
switch (propertyName) {
case Constants.PROP_RDFS_LABEL:
case Constants.PROP_SKOS_PREF_LABEL:
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/widoco/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,9 @@ public static String getIndexDocument(String resourcesFolderName, Configuration
document += " $(\"#introduction\").load(\"sections/introduction-" + c.getCurrentLanguage()
+ ".html\"); \n";
}
//namespace table is always a separated document
document += " $(\"#nstable\").load(\"sections/ns-" + c.getCurrentLanguage()
+ ".html\"); \n";
}
if (c.isIncludeOverview()){
if(c.getOverviewPath()!=null && !c.getOverviewPath().isEmpty()){
Expand Down Expand Up @@ -835,9 +838,10 @@ public static String getIndexDocument(String resourcesFolderName, Configuration
if (c.isIncludeAbstract())
document += " <div id=\"abstract\"></div>\n";
document += "<div id=\"toc\"></div>";
if (c.isIncludeIntroduction())
if (c.isIncludeIntroduction()) {
document += " <div id=\"introduction\"></div>\n";
// else document += "<div id=\"namespacedeclaration\"></div>\n";
document += " <div id=\"nstable\"></div>\n"; //ns declaration is part of the intro
}
if (c.isIncludeOverview())
document += " <div id=\"overview\"></div>\n";
if (c.isIncludeDescription())
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/widoco/CreateResources.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,23 @@ private static String createAbstractSection(String path, Configuration c, Proper
}

private static String createIntroductionSection(String path, Configuration c,Properties lang) {
String textToWrite;
String introText;
String nsText="";
HashMap<String,String> nsDecl = c.getNamespaceDeclarations();
if ((c.getIntroductionPath() != null) && (!"".equals(c.getIntroductionPath()))) {
textToWrite = WidocoUtils.readExternalResource(c.getIntroductionPath());
introText = WidocoUtils.readExternalResource(c.getIntroductionPath());
} else {
textToWrite = Constants.getIntroductionSectionTitleAndPlaceHolder(c, lang);
introText = Constants.getIntroductionSectionTitleAndPlaceHolder(c, lang);
if (nsDecl != null && !nsDecl.isEmpty()) {
textToWrite += Constants.getNameSpaceDeclaration(nsDecl, c, lang);
nsText = Constants.getNameSpaceDeclaration(nsDecl, c, lang);
}
//only save if separating sections
if(!c.isIncludeAllSectionsInOneDocument()){
saveDocument(path + File.separator + "introduction-" + c.getCurrentLanguage() + ".html", textToWrite,c);
saveDocument(path + File.separator + "introduction-" + c.getCurrentLanguage() + ".html", introText,c);
saveDocument(path + File.separator + "ns-" + c.getCurrentLanguage() + ".html", nsText,c);
}
}
return textToWrite;
return introText + nsText;
}

// the lists passed onto this method are the fixed lists
Expand Down
Binary file modified src/main/resources/lode.zip
Binary file not shown.
3 changes: 2 additions & 1 deletion src/main/resources/lode/extraction.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -1045,7 +1045,8 @@ http://www.oxygenxml.com/ns/doc/xsl ">
<dd>
<xsl:choose>
<xsl:when test="normalize-space(@*:resource) = ''">
<xsl:value-of select="$ontology-url"/>
<!--<xsl:value-of select="$ontology-url"/>-->
<xsl:value-of select="text()"/>
</xsl:when>
<xsl:otherwise>
<a href="{@*:resource}">
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/widoco/CreateDocInThreadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,31 @@ public void testAdvancedAnnotationsInOntology() {
fail("Error while running the test: " +e.getMessage());
}
}

/**
* Test to see if annotation properties that document the ontology and also are extended in the ontology itself
* are being recognized.
* Issue 530 (https://github.com/dgarijo/Widoco/issues/530)
*/
@org.junit.Test
public void testIssue530() {
try {
String pathToOnto = "test" + File.separator + "medatatestont.ttl";
c.setFromFile(true);
this.c.setOntologyPath(pathToOnto);
//read the model from file
WidocoUtils.loadModelToDocument(c);
c.loadPropertiesFromOntology(c.getMainOntology().getOWLAPIModel());
//title is the property being extended
if(c.getMainOntology().getTitle().isEmpty()){
fail("Could not extract title!");
}
//not needed, but added for consistency with the other tests.
CreateResources.generateDocumentation(c.getDocumentationURI(), c, c.getTmpFile());
}catch(Exception e){
fail("Error while running the test: " +e.getMessage());
}
}
//
/**
* This is a test to see if a big ontology works (several MB)
Expand Down
10 changes: 10 additions & 0 deletions test/example_test.owl
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ xsd:date rdf:type rdfs:Datatype .
rdfs:comment "This property links instances from Researcher to Organization"@en ;
rdfs:label "part of"@en .

### http://www.w3.org/2006/time#hasBeginning
<http://www.w3.org/2006/time#hasBeginning> rdf:type owl:ObjectProperty ;
rdfs:domain <http://www.w3.org/2006/time#TemporalEntity> ;
rdfs:range <http://www.w3.org/2006/time#Instant> ;
rdfs:comment "Beginning of a temporal entity."^^xsd:anyURI ;
rdfs:isDefinedBy "http://www.w3.org/2006/time"^^xsd:anyURI ;
rdfs:label "has beginning"^^xsd:anyURI .


#################################################################
# Data properties
Expand All @@ -146,6 +154,7 @@ xsd:date rdf:type rdfs:Datatype .

### http://xmlns.com/foaf/0.1/Organization
<http://xmlns.com/foaf/0.1/Organization> rdf:type owl:Class ;
rdfs:isDefinedBy <http://xmlns.com/foaf/0.1/> ;
owl:equivalentClass :Organization .


Expand All @@ -156,6 +165,7 @@ xsd:date rdf:type rdfs:Datatype .
skos:editorialNote "SKOS note"@en ;
owl:equivalentClass <http://xmlns.com/foaf/0.1/Organization>;
skos:prefLabel "organization";
rdfs:isDefinedBy <https://w3id.org/example> ;
rdfs:label "Organization"@en, "org"@fr .


Expand Down
13 changes: 13 additions & 0 deletions test/medatatestont.ttl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@prefix myont: <https://identifier.my.ont/ont/> .
@prefix dcterms: <http://purl.org/dc/terms/> .

<https://identifier.my.ont/ont/>
a owl:Ontology ;
rdfs:label "ontology";
dcterms:title "Example title" ;
.

<myont:citationtitle>
a owl:DatatypeProperty ;
rdfs:subPropertyOf dcterms:title ;
.

0 comments on commit 2ff38f5

Please sign in to comment.