Skip to content

Commit

Permalink
Eliminate one of three error types
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesaoverton committed Dec 10, 2020
1 parent bad7b69 commit 0868693
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 38 deletions.
16 changes: 4 additions & 12 deletions docs/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ When specifying the `--output` (or `--format` for converting), make sure the fil

### Invalid Element Error

This error usually appears when running [`template`](/template) and special characters are used within the local ID part of a CURIE or IRI (e.g., `obo:IAO?0000115` or `http://purl.obolibrary.org/obo/IAO:0000115`). Local IDs may only include alphanumeric characters, underscores, and dashes.
This error occurs when ROBOT tries to convert an IRI to an XML element name for writing but encounters an illegal character. Common illegal characters include `/` and `:`. This error usually occurs when creating new ontology terms with [`template`](/template). See [Namespaces in XML](https://www.w3.org/TR/REC-xml-names/) for full details on legal XML element names.

When rendering the output, only properties are validated for illegal characters. OWLAPI will allow local IDs with illegal characters to be used as subjects and objects.
The solution is usually to add a new [prefix](/global#prefixes) so that the illegal character is no longer part of the element name. For example, the prefix `ex` for `http://example.com/` is valid, and `http://example.com/foo/bar` is a valid IRI, but `ex:foo/bar` is not a valid element name. By defining a new prefix `foo` for `http://example.com/foo/` we can now use `foo:bar` as a valid element name for the same IRI `http://example.com/foo/bar`.

### Invalid Ontology File Error

Expand Down Expand Up @@ -64,14 +64,6 @@ When matching an IRI by pattern, the pattern should contain one or more wildcard

Prefixes (added with `--prefix`) should be strings in the following format: `"foo: http://foo/bar#"`. See [Prefixes](/global#prefixes) for more details on adding prefixes.

### Invalid QName Error

This error usually occurs when running [`template`](/template). When using a CURIE or IRI to point to a property in the ROBOT template string (e.g., `A <property>`), it must be a valid QName. When a QName is expanded, the *local* part of the ID (the part after the last `/` or `#`) must start with an alphabetic character. The following characters must be alphanumeric, underscores, or dashes.

For example, the IRI `http://purl.obolibrary.org/obo/BFO_0000001` is valid because the local part begins with the character `B`. This may be referenced with the CURIE `BFO:0000001`. The IRI `http://purl.obolibrary.org/obo/0000001` is **not** valid because the local part begins with the character `0`. Even though `obo:0000001` looks like a valid CURIE, it expands into an invalid QName.

When rendering the output, only properties are validated for QNames. OWLAPI will allow invalid QNames as subjects and objects.

### Invalid Reasoner Error

[Reason](/reason), [materialize](/materialize), and [reduce](/reduce) all expect `--reasoner` options. All three commands support `structural`, `hermit`, `jfact`, and `elk`. Only the reason command supports `emr`. Click on the command for more details
Expand Down Expand Up @@ -135,9 +127,9 @@ robot -p "robot: http://purl.obolibrary.org/robot/"

This error usually occurs when running [`template`](/template). If you use a CURIE in one of the ROBOT template strings as a property (e.g., `A ex:0000115`) but do not define the prefix of that CURIE, ROBOT will be unable to save the ontology file.

To resolve this, make sure all CURIEs use prefixes that are defined. ROBOT includes a set of [default prefixes](https://github.com/ontodev/robot/blob/master/robot-core/src/main/resources/obo_context.jsonld), but you can also define your own prefixes. To include a custom prefix, you see [prefixes](/global#prefixes).
To resolve this, make sure all CURIEs use prefixes that are defined. ROBOT includes a set of [default prefixes](https://github.com/ontodev/robot/blob/master/robot-core/src/main/resources/obo_context.jsonld), but you can also define your own prefixes. To include a custom prefix, see [prefixes](/global#prefixes).

When rendering the output, only properties are validated for QNames. OWLAPI will allow undefined prefixes to be used in subjects and objects, but the IRI will be the unexpanded version of the CURIE (i.e., the IRI will just be `ex:0000115`).
When rendering the output, only properties are validated for [QNames](https://en.wikipedia.org/wiki/QName). OWLAPI will allow undefined prefixes to be used in subjects and objects, but the IRI will be the unexpanded version of the CURIE (i.e., the IRI will just be `ex:0000115`).

### Unknown Arg Error

Expand Down
27 changes: 1 addition & 26 deletions robot-core/src/main/java/org/obolibrary/robot/IOHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ public class IOHelper {
private static final String invalidElementError =
NS + "INVALID ELEMENT ERROR \"%s\" contains invalid characters";

private static final String invalidQNameError =
NS + "INVALID QNAME ERROR \"%s\" cannot be converted to a QName";

/** Error message when the specified file cannot be loaded. Expects the file name. */
private static final String invalidOntologyFileError =
NS + "INVALID ONTOLOGY FILE ERROR Could not load a valid ontology from file: %s";
Expand Down Expand Up @@ -1251,24 +1248,6 @@ public static boolean isValidCURIE(CharSequence s) {
return true;
}

/**
* Determine if the short form of an IRI contains invalid characters.
*
* @param iri IRI to check
* @return true if no invalid characters found
*/
public static boolean shortFormIsValid(IRI iri) {
String s = iri.getShortForm();
for (int i = 0; i < s.length(); ) {
int codePoint = Character.codePointAt(s, i);
if (!XMLUtils.isXMLNameChar(codePoint)) {
return false;
}
i += Character.charCount(codePoint);
}
return true;
}

/**
* Read comma-separated values from a path to a list of lists of strings.
*
Expand Down Expand Up @@ -1596,11 +1575,7 @@ private void saveOntologyFile(
String prefix = element.split(":")[0];
throw new IOException(String.format(undefinedPrefixError, e2.getElementName(), prefix));
} else {
if (shortFormIsValid(IRI.create(element))) {
throw new IOException(String.format(invalidElementError, element));
} else {
throw new IOException(String.format(invalidQNameError, element));
}
throw new IOException(String.format(invalidElementError, element));
}
}
throw new IOException(String.format(ontologyStorageError, ontologyIRI.toString()), e);
Expand Down

0 comments on commit 0868693

Please sign in to comment.