Repository: SynBioDex/tyto (language: python)

Issue:
From term to variable?
What's the general system for going from term to variable?

This is similar to the recently resolved #29, only I'm encountering it with the SBO variable for "non-coding RNA".

```
> tyto.SBO.get_uri_by_term('non-coding RNA')
'https://identifiers.org/SBO:0000334'
> tyto.SBO.non_coding_RNA
LookupError: non_coding_RNA is not a valid ontology term
> tyto.SBO.non_coding_rna 
LookupError: non_coding_RNA is not a valid ontology term
```

Can we document this as well?


Discussion / hints:
Another piece to add besides documentation: a "URI to variable name" function?
May be partially obsoleted by #26

Fix patch:
diff --git a/tyto/endpoint/endpoint.py b/tyto/endpoint/endpoint.py
index 3f13e19..e2e0dd9 100644
--- a/tyto/endpoint/endpoint.py
+++ b/tyto/endpoint/endpoint.py
@@ -66,26 +66,18 @@ def get_uri_by_term(self, ontology: "Ontology", term: str) -> str:
             {{from_clause}}
             WHERE
             {{{{
-                optional 
                 {{{{
-                    ?uri rdfs:label "{term}"@en
-                }}}}
-                optional
-                {{{{ 
-                    ?uri rdfs:label "{term}"
-                }}}}
-                optional
-                {{{{ 
-                    ?uri rdfs:label "{term}"^^xsd:string
+                    ?uri rdfs:label ?term
                 }}}}
+                FILTER(REGEX(?term, '{term}', "i"))
             }}}}
-            '''.format(term=term)
+            '''.format(term='^' + term.replace(' ', r'[\\-\\_\\s]') + '$')
         error_msg = '{} not a valid ontology term'.format(term)
         response = self.query(ontology, query, error_msg)
         if not response:
             return None
         if len(response) > 1:
-            raise Exception('Ambiguous term--more than one matching URI found')
+            raise Exception(f'Ambiguous term {term}--more than one matching URI found')
         response = response[0]
         return response
 
@@ -317,8 +309,8 @@ def get_uri_by_term(self, ontology: "Ontology", term: str):
             response = response.json()
             if not response or not len(response['response']['docs']):
                 return None
-            if len(response['response']['docs']) > 1 and response['response']['docs'][0]['label'] == response['response']['docs'][1]['label']:
-                raise Exception('Ambiguous term--more than one matching URI found')
+            #if len(response['response']['docs']) > 1 and response['response']['docs'][0]['label'] == response['response']['docs'][1]['label']:
+            #    raise Exception('Ambiguous term--more than one matching URI found')
             return response['response']['docs'][0]['iri']
         raise urllib.error.HTTPError(get_query, response.status_code, response.reason, response.headers, None)
 


Test patch:
diff --git a/test/test_ontology.py b/test/test_ontology.py
index 833aac7..15cc63f 100644
--- a/test/test_ontology.py
+++ b/test/test_ontology.py
@@ -83,6 +83,9 @@ def test_ancestors(self):
         self.assertTrue(SO.promoter.is_ancestor_of(SO.RNApol_III_promoter))
         self.assertFalse(SO.promoter.is_descendant_of(SO.RNApol_III_promoter))
 
+    def test_case_insensitivity(self):
+        self.assertEqual(SBO.NON_CODING_RNA, SBO.non_coding_rna)
+
     def test_nonunique_labels(self):
         test_ontology = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'test_case_0.owl')
         o = Ontology(path=test_ontology,
@@ -98,6 +101,7 @@ def test_get_ontologies(self):
                         ['http://purl.obolibrary.org/obo/gno.owl'],
                         'gno')
 
+
 class TestOLS(unittest.TestCase):
 
     SO_endpoints = SO.endpoints