Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix referencing properties by CURIE in export #722

Merged
merged 3 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Handle empty [`template`] property charactersitics in [#719]
- Fix referencing properties by CURIE in [`export`] in [#722]

## [1.7.0] - 2020-07-31

Expand Down Expand Up @@ -198,6 +199,7 @@ First official release of ROBOT!
[`template`]: http://robot.obolibrary.org/template
[`validate`]: http://robot.obolibrary.org/validate

[#722]: https://github.com/ontodev/robot/pull/722
[#719]: https://github.com/ontodev/robot/pull/716
[#715]: https://github.com/ontodev/robot/pull/715
[#710]: https://github.com/ontodev/robot/pull/710
Expand Down
104 changes: 65 additions & 39 deletions robot-core/src/main/java/org/obolibrary/robot/ExportOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,20 +217,47 @@ public static Table createExportTable(
currentEntitySelect = "NAMED";
}

// Maybe get a property
OWLAnnotationProperty ap = checker.getOWLAnnotationProperty(colName, false);
OWLAnnotationProperty ap = null;

// Handle some defaults
IRI colIRI = ioHelper.createIRI(colName);
if (colIRI != null
&& colIRI.toString().equals(dataFactory.getRDFSLabel().getIRI().toString())) {
// Handle rdfs:label defaults
if (iri != null && iri.equals(dataFactory.getRDFSLabel().getIRI())) {
currentEntityFormat = "LABEL";
currentEntitySelect = "NAMED";
ap = dataFactory.getRDFSLabel();
}

OWLDataProperty dp = checker.getOWLDataProperty(colName);
OWLObjectProperty op = checker.getOWLObjectProperty(colName);
// checker only resolves labels, so try with IRI
if (ap == null && iri != null && ontology.containsAnnotationPropertyInSignature(iri)) {
ap = dataFactory.getOWLAnnotationProperty(iri);
} else {
// Try by label
ap = checker.getOWLAnnotationProperty(colName);
}

// Check for object/data properties if not an annotation property
OWLDataProperty dp = null;
OWLObjectProperty op = null;
if (ap == null) {
// annotation property not found
if (iri != null && ontology.containsDataPropertyInSignature(iri)) {
// Use IRI to create data property
dp = dataFactory.getOWLDataProperty(iri);
} else {
// Try by label
dp = checker.getOWLDataProperty(colName);
}

if (dp == null) {
// data property not found
if (iri != null && ontology.containsObjectPropertyInSignature(iri)) {
// Use IRI to create object property
op = dataFactory.getOWLObjectProperty(iri);
} else {
// Try by label
op = checker.getOWLObjectProperty(colName);
}
}
}

// Maybe get a short form provider
ShortFormProvider provider;
Expand Down Expand Up @@ -342,8 +369,8 @@ public static void saveTable(Table table, String exportPath, Map<String, String>
* @param rt RendererType to use to render Manchester
* @param provider ShortFormProvider to resolve entities
* @param classes Set of class expressions to convert to string
* @param includeNamed
* @param includeAnonymous
* @param includeNamed if true, include named classes in output
* @param includeAnonymous if true, include anonymous classes in output
* @return String of class expressions or null
*/
private static List<String> classExpressionsToString(
Expand Down Expand Up @@ -374,8 +401,8 @@ private static List<String> classExpressionsToString(
* @param displayRendererType RendererType for display value
* @param sortRendererType RendererType for sort value
* @param provider ShortFormProvider to resolve entities
* @param includeNamed
* @param includeAnonymous
* @param includeNamed if true, include named classes in output
* @param includeAnonymous if true, include anonymous classes in output
* @return Cell for this Column containing class expressions
*/
private static Cell getClassCell(
Expand Down Expand Up @@ -502,8 +529,8 @@ private static Cell getEntityTypeCell(EntityType type, Column column) {
* @param displayRendererType RendererType for display value
* @param sortRendererType RendererType for sort value
* @param provider ShortFormProvider to resolve entities
* @param includeNamed
* @param includeAnonymous
* @param includeNamed if true, include named classes in output
* @param includeAnonymous if true, include anonymous classes in output
* @return Cell for this Column containing property expressions
*/
private static Cell getPropertyCell(
Expand Down Expand Up @@ -548,7 +575,7 @@ private static List<String> getPropertyValues(
List<String> values = new ArrayList<>();
for (OWLAnnotationAssertionAxiom a :
EntitySearcher.getAnnotationAssertionAxioms(entity, ontology)) {
if (a.getProperty().getIRI() == ap.getIRI()) {
if (a.getProperty().getIRI().equals(ap.getIRI())) {
if (a.getValue().isIRI()) {
IRI iri = a.getValue().asIRI().orNull();
if (iri != null) {
Expand All @@ -575,8 +602,8 @@ private static List<String> getPropertyValues(
* @param provider ShortFormProvider to resolve entities
* @param entity OWLEntity to get relations of
* @param dp OWLDataProperty to get the value(s) of
* @param includeNamed
* @param includeAnonymous
* @param includeNamed if true, include named classes in output
* @param includeAnonymous if true, include anonymous classes in output
* @return String of values or null
*/
private static List<String> getPropertyValues(
Expand Down Expand Up @@ -631,8 +658,8 @@ private static List<String> getPropertyValues(
* @param provider ShortFormProvider to resolve entities
* @param entity OWLEntity to get annotations on
* @param op OWLObjectProperty to get the value(s) of
* @param includeNamed
* @param includeAnonymous
* @param includeNamed if true, include named classes in output
* @param includeAnonymous if true, include anonymous classes in output
* @return String of values or null
*/
private static List<String> getPropertyValues(
Expand Down Expand Up @@ -691,8 +718,8 @@ private static List<String> getPropertyValues(
* @param dp OWLDataProperty to look for
* @param rt RendererType to use to render Manchester
* @param provider ShortFormProvider to resolve entities
* @param includeNamed
* @param includeAnonymous
* @param includeNamed if true, include named classes in output
* @param includeAnonymous if true, include anonymous classes in output
* @return set of fillers that are 'values' of the data property
*/
private static Set<String> getRestrictionFillers(
Expand All @@ -716,7 +743,7 @@ private static Set<String> getRestrictionFillers(
pe = avf.getProperty();
if (!pe.isAnonymous()) {
OWLDataProperty prop = pe.asOWLDataProperty();
if (prop.getIRI() == dp.getIRI()) {
if (prop.getIRI().equals(dp.getIRI())) {
if ((!f.isAnonymous() && includeNamed) || (f.isAnonymous() && includeAnonymous)) {
fillers.add(renderRestrictionString(rt, provider, f, null));
}
Expand All @@ -729,7 +756,7 @@ private static Set<String> getRestrictionFillers(
pe = svf.getProperty();
if (!pe.isAnonymous()) {
OWLDataProperty prop = pe.asOWLDataProperty();
if (prop.getIRI() == dp.getIRI()) {
if (prop.getIRI().equals(dp.getIRI())) {
if ((!f.isAnonymous() && includeNamed) || (f.isAnonymous() && includeAnonymous)) {
fillers.add(renderRestrictionString(rt, provider, f, null));
}
Expand All @@ -743,7 +770,7 @@ private static Set<String> getRestrictionFillers(
n = ec.getCardinality();
if (!pe.isAnonymous()) {
OWLDataProperty prop = pe.asOWLDataProperty();
if (prop.getIRI() == dp.getIRI()) {
if (prop.getIRI().equals(dp.getIRI())) {
if ((!f.isAnonymous() && includeNamed) || (f.isAnonymous() && includeAnonymous)) {
fillers.add(renderRestrictionString(rt, provider, f, n));
}
Expand All @@ -757,7 +784,7 @@ private static Set<String> getRestrictionFillers(
n = minc.getCardinality();
if (!pe.isAnonymous()) {
OWLDataProperty prop = pe.asOWLDataProperty();
if (prop.getIRI() == dp.getIRI()) {
if (prop.getIRI().equals(dp.getIRI())) {
if ((!f.isAnonymous() && includeNamed) || (f.isAnonymous() && includeAnonymous)) {
fillers.add(renderRestrictionString(rt, provider, f, n));
}
Expand All @@ -771,7 +798,7 @@ private static Set<String> getRestrictionFillers(
n = maxc.getCardinality();
if (!pe.isAnonymous()) {
OWLDataProperty prop = pe.asOWLDataProperty();
if (prop.getIRI() == dp.getIRI()) {
if (prop.getIRI().equals(dp.getIRI())) {
if ((!f.isAnonymous() && includeNamed) || (f.isAnonymous() && includeAnonymous)) {
fillers.add(renderRestrictionString(rt, provider, f, n));
}
Expand All @@ -793,8 +820,8 @@ private static Set<String> getRestrictionFillers(
* @param op OWLObjectProperty to look for
* @param rt RendererType to use to render Manchester
* @param provider ShortFormProvider to resolve entities
* @param includeNamed
* @param includeAnonymous
* @param includeNamed if true, include named classes in output
* @param includeAnonymous if true, include anonymous classes in output
* @return set of fillers that are 'values' of the object property
*/
private static Set<String> getRestrictionFillers(
Expand All @@ -819,7 +846,7 @@ private static Set<String> getRestrictionFillers(
f = avf.getFiller();
if (!pe.isAnonymous()) {
OWLObjectProperty prop = pe.asOWLObjectProperty();
if (prop.getIRI() == op.getIRI()) {
if (prop.getIRI().equals(op.getIRI())) {
if ((f.isAnonymous() && includeAnonymous) || (!f.isAnonymous() && includeNamed)) {
fillers.add(renderRestrictionString(rt, provider, f, null));
}
Expand All @@ -833,7 +860,7 @@ private static Set<String> getRestrictionFillers(
f = svf.getFiller();
if (!pe.isAnonymous()) {
OWLObjectProperty prop = pe.asOWLObjectProperty();
if (prop.getIRI() == op.getIRI()) {
if (prop.getIRI().equals(op.getIRI())) {
if ((f.isAnonymous() && includeAnonymous) || (!f.isAnonymous() && includeNamed)) {
fillers.add(renderRestrictionString(rt, provider, f, null));
}
Expand All @@ -848,7 +875,7 @@ private static Set<String> getRestrictionFillers(
n = ec.getCardinality();
if (!pe.isAnonymous()) {
OWLObjectProperty prop = pe.asOWLObjectProperty();
if (prop.getIRI() == op.getIRI()) {
if (prop.getIRI().equals(op.getIRI())) {
if ((f.isAnonymous() && includeAnonymous) || (!f.isAnonymous() && includeNamed)) {
fillers.add(renderRestrictionString(rt, provider, f, n));
}
Expand All @@ -863,7 +890,7 @@ private static Set<String> getRestrictionFillers(
n = minc.getCardinality();
if (!pe.isAnonymous()) {
OWLObjectProperty prop = pe.asOWLObjectProperty();
if (prop.getIRI() == op.getIRI()) {
if (prop.getIRI().equals(op.getIRI())) {
if ((f.isAnonymous() && includeAnonymous) || (!f.isAnonymous() && includeNamed)) {
fillers.add(renderRestrictionString(rt, provider, f, n));
}
Expand All @@ -878,7 +905,7 @@ private static Set<String> getRestrictionFillers(
n = maxc.getCardinality();
if (!pe.isAnonymous()) {
OWLObjectProperty prop = pe.asOWLObjectProperty();
if (prop.getIRI() == op.getIRI()) {
if (prop.getIRI().equals(op.getIRI())) {
if ((f.isAnonymous() && includeAnonymous) || (!f.isAnonymous() && includeNamed)) {
fillers.add(renderRestrictionString(rt, provider, f, n));
}
Expand Down Expand Up @@ -927,9 +954,9 @@ private static Row getRow(OWLOntology ontology, Table table, OWLEntity entity) t
boolean includeAnonymous = col.getIncludeAnonymous();

String colName = col.getName();
OWLProperty maybeAnnotation = col.getProperty();
if (maybeAnnotation instanceof OWLAnnotationProperty) {
OWLAnnotationProperty maybeLabel = (OWLAnnotationProperty) maybeAnnotation;
OWLProperty colProperty = col.getProperty();
if (colProperty instanceof OWLAnnotationProperty) {
OWLAnnotationProperty maybeLabel = (OWLAnnotationProperty) colProperty;
if (maybeLabel.isLabel()) {
// Handle like we do default LABEL columns
colName = "LABEL";
Expand Down Expand Up @@ -982,7 +1009,6 @@ private static Row getRow(OWLOntology ontology, Table table, OWLEntity entity) t
}

// If a property exists, use this property to get values
OWLProperty colProperty = col.getProperty();
if (colProperty != null) {
if (colProperty instanceof OWLAnnotationProperty) {
OWLAnnotationProperty ap = (OWLAnnotationProperty) colProperty;
Expand Down Expand Up @@ -1306,8 +1332,8 @@ private static List<String> getSynonyms(OWLOntology ontology, OWLEntity entity)
* @param rt RendererType to use to render Manchester
* @param provider ShortFormProvider to resolve entities
* @param props Set of property expressions to convert to string
* @param includeNamed
* @param includeAnonymous
* @param includeNamed if true, include named classes in output
* @param includeAnonymous if true, include anonymous classes in output
* @return String of property expressions or null
*/
private static List<String> propertyExpressionsToString(
Expand Down