Repository: INCATools/dead_simple_owl_design_patterns (language: python)

Issue:
simple tester falsly fails on single quote
```
  text: "An instance of %s that is caused by an inherited modification of the individual's genome."
```

causes the simple-tester validation script to fail with the remark:

`warnings.warn("text field '%s' has an odd number of single quotes." % val)`


Discussion / hints:
The test is required for Manchester syntax text fields, as single quotes are used to delimit/identify owl entities.   It could potentially be dropped for fields with literal values like this, but that  is not straightforward - the test currently runs on any field named 'text' and there is currently no simple way to identify Manchester Syntax fields (Might be possible to derive from schema with a better JSON schema lib; but can't be done with current one).

I suspect that the only viable solution is to add support for escaping (with backslash).  Would that be OK?
Yeah I think so! But if we do that, we should make respective warning in the simple tester (unescaped ')
Agreed.
I suspect that escapes will need support in dosdp tools if we want to avoid them ending up as literal text.  @balhoff - is this correct?

Would prefer this to be in place before changing test.
@balhoff @dosumis whats the status of this? causing some problems for me :)
Do we have an escape decided?
Would `\`be sufficient?
Update—we had some discussion offline. I lean against adding escapes for this situation. Mainly because the text fields causing the errors don't have a meaning for balanced quotes, and shouldn't need to escape them. The text fields requiring balanced quotes (Manchester syntax) don't allow quotes for any other purpose (we recently tightened up the allowed regex for variable names), and so also don't need to escape them. That pushes back the issue to changing the validator (sorry @dosumis).

Fix patch:
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..58a1303
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+venv
+.idea
+**/.DS_Store
+
diff --git a/.travis.yml b/.travis.yml
index b5598d5..f56fc5e 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,20 +8,8 @@ python:
 install:
    - pip install -r requirements.txt
 
-# Jython script testing disabled.  The purpose of this travis job is currently to test 
-# that schema docs are valid an can be used to validate a standard set of test patterns.
-
-# install jython
-# before_install:
-#  - export JYTHON_URL='http://central.maven.org/maven2/org/python/jython-installer/2.7.0/jython-installer-2.7.0.jar'
-#  - wget $JYTHON_URL -O jython_installer.jar; java -jar jython_installer.jar -s -d $HOME/jython; export PATH=$HOME/jython/bin:$PATH;jython --version
-
-# before_script:
-#  - jython -c "print ''"    # Before run the test case, we need to make jython run some code
-#  - mvn package             # use maven to assemble java jar dependencies in lib folder
-#  - export CLASSPATH=lib/*  # set up class using a wildcard (supported as of Java 6 or later)
-
-# test script
 script:
    - cd spec
    - python test_schema.py
+   - cd ../src
+   - python simple_pattern_tester.py ../spec/test
diff --git a/requirements.txt b/requirements.txt
index 1fadec9..ab45728 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,7 @@
 PyYAML
 jsonschema
+requests
+jsonpath_rw
+ruamel.yaml
+
 


Test patch:
diff --git a/spec/test/cellPartOfAnatomicalEntity.yaml b/spec/test/cellPartOfAnatomicalEntity.yaml
new file mode 100644
index 0000000..c508126
--- /dev/null
+++ b/spec/test/cellPartOfAnatomicalEntity.yaml
@@ -0,0 +1,38 @@
+pattern_name: cellPartOfAnatomicalEntity
+pattern_iri: http://purl.obolibrary.org/obo/cl/cellPartOfAnatomicalEntity
+
+description: A cell that is part of an anatomical entity.
+#examples: CL_0009001 compound eye retinal cell, CL_2000004 pituitary gland cell (654 total)
+
+contributors:
+  - https://orcid.org/0000-0001-5208-3432
+  - https://orcid.org/0000-0002-6601-2165
+
+classes:
+  cell: "CL:0000000"
+  anatomical entity: "UBERON:0001062"
+
+relations:
+  part of: "BFO:0000050"
+
+vars:
+  cell: "'cell'"
+  anatomical_entity: "'anatomical entity'"
+
+name:
+  text: "%s %s"
+  vars:
+    - cell
+    - anatomical_entity
+
+def:
+  text: "Any %s that is part of a %s."
+  vars:
+    - cell
+    - anatomical_entity
+
+equivalentTo:
+  text: "%s and ('part of' some %s)"
+  vars:
+    - cell
+    - anatomical_entity
diff --git a/src/simple_pattern_tester.py b/src/simple_pattern_tester.py
index 22448ab..e89569d 100755
--- a/src/simple_pattern_tester.py
+++ b/src/simple_pattern_tester.py
@@ -1,4 +1,5 @@
 #!/usr/bin/env python3
+
 from jsonschema import Draft7Validator
 import sys
 import glob
@@ -56,11 +57,13 @@ def test_text_fields(pattern):
     owl_entities = set()
     if 'classes' in pattern.keys(): owl_entities.update(set(pattern['classes'].keys()))
     if 'relations' in pattern.keys(): owl_entities.update(set(pattern['relations'].keys()))
-    expr = parse('*..text')
-    text_fields = [match for match in expr.find(pattern)]
+    expr = parse('logical_axioms.[*].text')
+    ms_fields = [match for match in expr.find(pattern)]
+    expr = parse('equivalentTo|subClassOf|GCI|disjointWith.text')
+    ms_fields.extend([match for match in expr.find(pattern)])
     stat=True
-    if text_fields:
-        for field in text_fields:
+    if ms_fields:
+        for field in ms_fields:
             # Test for even number single quotes
             val = field.value
             m = re.findall("'", val)