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

Multi annotation column #1205

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions docs/examples/multi_annotations_header_new.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Term Term ID Annotations
LABEL ID AP


2 changes: 2 additions & 0 deletions docs/examples/multi_annotations_header_old.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
LABEL ID A acme:p-0000000049 A acme:p-0000000050 A acme:p-0000000051

67 changes: 67 additions & 0 deletions docs/examples/multi_annotations_new.owl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://www.w3.org/2002/07/owl"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:acme="https://shangrila.ef.zz/ontology/acme/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<Ontology/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Annotation properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- https://shangrila.ef.zz/ontology/acme/p-0000000049 -->

<AnnotationProperty rdf:about="https://shangrila.ef.zz/ontology/acme/p-0000000049"/>



<!-- https://shangrila.ef.zz/ontology/acme/p-0000000050 -->

<AnnotationProperty rdf:about="https://shangrila.ef.zz/ontology/acme/p-0000000050"/>



<!-- https://shangrila.ef.zz/ontology/acme/p-0000000051 -->

<AnnotationProperty rdf:about="https://shangrila.ef.zz/ontology/acme/p-0000000051"/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- https://shangrila.ef.zz/ontology/acme/s-0000014176 -->

<Class rdf:about="https://shangrila.ef.zz/ontology/acme/s-0000014176">
<rdfs:label>ACME Communications INC</rdfs:label>
<acme:p-0000000049> Value ZZ</acme:p-0000000049>
<acme:p-0000000050>ABCD 1234</acme:p-0000000050>
<acme:p-0000000051>CBS ABC,CNN,PBS</acme:p-0000000051>
</Class>
</rdf:RDF>



<!-- Generated by the OWL API (version 4.5.26) https://github.com/owlcs/owlapi -->

2 changes: 2 additions & 0 deletions docs/examples/multi_annotations_new.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Term Term ID Annotations
ACME Communications INC acme:s-0000014176 acme:p-0000000049 " Value ZZ"|acme:p-0000000050 "ABCD 1234"|acme:p-0000000051 "CBS ABC,CNN,PBS"
67 changes: 67 additions & 0 deletions docs/examples/multi_annotations_old.owl
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0"?>
<rdf:RDF xmlns="http://www.w3.org/2002/07/owl#"
xml:base="http://www.w3.org/2002/07/owl"
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:acme="https://shangrila.ef.zz/ontology/acme/"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<Ontology/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Annotation properties
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- https://shangrila.ef.zz/ontology/acme/p-0000000049 -->

<AnnotationProperty rdf:about="https://shangrila.ef.zz/ontology/acme/p-0000000049"/>



<!-- https://shangrila.ef.zz/ontology/acme/p-0000000050 -->

<AnnotationProperty rdf:about="https://shangrila.ef.zz/ontology/acme/p-0000000050"/>



<!-- https://shangrila.ef.zz/ontology/acme/p-0000000051 -->

<AnnotationProperty rdf:about="https://shangrila.ef.zz/ontology/acme/p-0000000051"/>



<!--
///////////////////////////////////////////////////////////////////////////////////////
//
// Classes
//
///////////////////////////////////////////////////////////////////////////////////////
-->




<!-- https://shangrila.ef.zz/ontology/acme/s-0000014176 -->

<Class rdf:about="https://shangrila.ef.zz/ontology/acme/s-0000014176">
<rdfs:label>ACME Communications INC</rdfs:label>
<acme:p-0000000049> Value ZZ</acme:p-0000000049>
<acme:p-0000000050>ABCD 1234</acme:p-0000000050>
<acme:p-0000000051>CBS ABC,CNN,PBS</acme:p-0000000051>
</Class>
</rdf:RDF>



<!-- Generated by the OWL API (version 4.5.26) https://github.com/owlcs/owlapi -->

2 changes: 2 additions & 0 deletions docs/examples/multi_annotations_old.tsv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Term Term ID classification1 classification2 classification3
ACME Communications INC acme:s-0000014176 (U) CBS ABC,CNN,PBS
6 changes: 6 additions & 0 deletions docs/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,12 @@ robot template --template animals_template_error.tsv \
--ext-template animals_ext_template.tsv \
--output results/animals_ext_template.owl
```
MEKS ROBOT multi annotation in a single column

robot template --prefix "acme: https://shangrila.ef.zz/ontology/acme/" \
--template multi_annotations_new.tsv \
--external-template multi_annotations_header_new.tsv
--output results/multi_annotations_new.owl


\* NOTE: the imports would be merged into the output if `--collapse-import-closure true` is included instead.
Expand Down
32 changes: 30 additions & 2 deletions robot-core/src/main/java/org/obolibrary/robot/Template.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.obolibrary.robot;

import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -877,8 +879,34 @@ private void addClassAxioms(IRI iri, List<String> row) throws Exception {
if (value == null || value.trim().isEmpty()) {
continue;
}

if (template.startsWith("A") || template.startsWith("LABEL")) {
if (template.equals("AP")) {
// split multi annotation string
// Ex meks:p-0000000049 "(U)"|meks:p-0000000050 "KECF6"|meks:p-0000000051 "SATL,COMMO,RODNIK
CharacterIterator it = new StringCharacterIterator(value);

// Iterate and print current character
String token = new String();
List<String> annotation_list = new ArrayList<>();
while (it.current() != CharacterIterator.DONE) {
if (it.current() != '|') {
token += it.current();
} else {
annotation_list.add(token);
token = "";
}
it.next();
}
annotation_list.add(token);
// ListString annotation_list[] = value.split("|");
Set<OWLAnnotation> annotations = new HashSet<>();
for (String annotation : annotation_list) {
annotations.addAll(getAnnotations(template, annotation, row, column));
}
// MultiAnnotation
for (OWLAnnotation annotation : annotations) {
axioms.add(dataFactory.getOWLAnnotationAssertionAxiom(iri, annotation));
}
} else if (template.startsWith("A") || template.startsWith("LABEL")) {
// Handle class annotations
Set<OWLAnnotation> annotations = getAnnotations(template, value, row, column);
for (OWLAnnotation annotation : annotations) {
Expand Down
13 changes: 11 additions & 2 deletions robot-core/src/main/java/org/obolibrary/robot/TemplateHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,10 @@ public static Set<OWLAnnotation> getAnnotations(
if (template.startsWith(">")) {
template = template.substring(1);
}

if (template.startsWith("A ") || template.startsWith("C ")) {
if (template.equals("AP")) {
// MultiAnnotation
return getStringAnnotations(checker, template, split, value, column);
} else if (template.startsWith("A ") || template.startsWith("C ")) {
return getStringAnnotations(checker, template, split, value, column);
} else if (template.startsWith("AT ") || template.startsWith("CT ")) {
if (template.contains("^^")) {
Expand Down Expand Up @@ -717,6 +719,10 @@ public static Set<OWLAnnotation> getStringAnnotations(
if (template.equals("LABEL")) {
// Handle special LABEL case
property = dataFactory.getRDFSLabel();
} else if (template.equals("AP")) {
String name = value.split(" ")[0];
value = value.substring(name.length() + 2).replaceAll("^\"|\"$", "");
property = getAnnotationProperty(checker, name, column);
} else {
String name = template.substring(1).trim();
property = getAnnotationProperty(checker, name, column);
Expand Down Expand Up @@ -930,6 +936,9 @@ public static boolean validateTemplateString(String template) {
} else if (template.matches("^(P .*|PI.?|[SEDI]P .*)")) {
// Properties can be P, PI (does not need to be followed by space), SP, EP, DP, or IP
return true;
} else if (template.equals("AP")) {
// AP multi annotation type
return true;
} else
// Individuals can be I, II (does not need to be followed by space), SI, or DI
return template.matches("^(I .*|II.?|[TSD]I .*)");
Expand Down
Loading