Skip to content

Commit

Permalink
Merge branch 'issue#16-namespace'
Browse files Browse the repository at this point in the history
  • Loading branch information
Carsten Fortmann-Grote committed Dec 19, 2024
2 parents 0e7e0b0 + 18bf5cc commit 48c95d5
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 75 deletions.
75 changes: 39 additions & 36 deletions ontop/omemap.obda
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,21 @@ source select
left join projectdatasetlink as _projectdatasetlink on _project.id = _projectdatasetlink.parent

mappingId MAPID-project(3)
target ome_instance:Project/{project_id} a ome_core:Project ; <{map_key}> {map_value} .
target ome_instance:Project/{project_id} a ome_core:Project ; <{map_key}> {map_value}^^xsd:string .
source select
_project.id as project_id,
concat( regexp_replace(
regexp_replace(
case
when _annotation.ns is null then 'www.openmicroscopy.org/ns/default'
else _annotation.ns
end,
'^([^h])',
'http://\1'),
'([^\/,#])$',
'\1/'
),
concat(regexp_replace(regexp_replace(
case
when _annotation.ns is null then 'http://www.openmicroscopy.org/ns/default/'
else
case
when starts_with(_annotation.ns, 'http') then _annotation.ns
else concat('http://', _annotation.ns)
end
end,
'([^\/,#])$',
'\1/'
), '\s', '_') ,
_annotation_mapvalue.name) as map_key,
_annotation_mapvalue.value as map_value
from project as _project
Expand All @@ -70,21 +71,22 @@ source select
left join datasetimagelink as _datasetimagelink on _dataset.id = _datasetimagelink.parent

mappingId MAPID-dataset-2
target ome_instance:Dataset/{dataset_id} <{map_key}> {map_value} .
target ome_instance:Dataset/{dataset_id} <{map_key}> {map_value}^^xsd:string .
source select
_dataset.id as dataset_id,
_datasetannotationlink.child as annotation_id,
concat( regexp_replace(
regexp_replace(
case
when _annotation.ns is null then 'www.openmicroscopy.org/ns/default'
else _annotation.ns
end,
'^([^h])',
'http://\1'),
'([^\/,#])$',
'\1/'
),
concat(regexp_replace(regexp_replace(
case
when _annotation.ns is null then 'http://www.openmicroscopy.org/ns/default/'
else
case
when starts_with(_annotation.ns, 'http') then _annotation.ns
else concat('http://', _annotation.ns)
end
end,
'([^\/,#])$',
'\1/'
), '\s', '_'),
_annotation_mapvalue.name) as map_key,
_annotation_mapvalue.value as map_value
from dataset as _dataset
Expand All @@ -102,20 +104,21 @@ source select
from image as _image

mappingId MAPID-Image-1
target ome_instance:Image/{image_id} a ome_core:Image; <{map_key}> {map_value} .
target ome_instance:Image/{image_id} a ome_core:Image; <{map_key}> {map_value}^^xsd:string .
source select
_image.id as image_id,
concat( regexp_replace(
regexp_replace(
case
when _annotation.ns is null then 'www.openmicroscopy.org/ns/default'
else _annotation.ns
end,
'^([^h])',
'http://\1'),
'([^\/,#])$',
'\1/'
),
concat(regexp_replace(regexp_replace(
case
when _annotation.ns is null then 'http://www.openmicroscopy.org/ns/default/'
else
case
when starts_with(_annotation.ns, 'http') then _annotation.ns
else concat('http://', _annotation.ns)
end
end,
'([^\/,#])$',
'\1/'
), '\s', '_'),
_annotation_mapvalue.name) as map_key,
_annotation_mapvalue.value as map_value
from image as _image
Expand Down
76 changes: 39 additions & 37 deletions queries/sql/targets.org
Original file line number Diff line number Diff line change
Expand Up @@ -414,44 +414,46 @@ ORDER BY table_name;
:END:

#+begin_src sql :engine postgres :dbhost localhost :dbport 15432 :dbuser ontop :dbpassword !ontop$ :database postgres
select regexp_replace(
regexp_replace(
case
when annotation.ns is null then 'www.openmicroscopy.org/ns/default'
else annotation.ns
end,
'^([^h])',
'http://\1'),
'([^\/,#])$',
'\1/'
)
as ns, annotation.ns
from annotation;
select regexp_replace(regexp_replace(
case
when annotation.ns is null then 'http://www.openmicroscopy.org/ns/default/'
else
case
when starts_with(annotation.ns, 'http') then annotation.ns
else concat('http://', annotation.ns)
end
end,
'([^\/,#])$',
'\1/'
), '\s', '_')
as ns, annotation.ns
from annotation;
#+end_src

#+RESULTS:
| ns | ns |
|-------------------------------------------+-----------------------------------|
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://www.openmicroscopy.org/ns/default/ | |
| http://www.openmicroscopy.org/ns/default/ | |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://www.openmicroscopy.org/ns/default/ | www.openmicroscopy.org/ns/default |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://www.openmicroscopy.org/ns/default/ | |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://www.openmicroscopy.org/ns/default/ | |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://www.openmicroscopy.org/ns/default/ | |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| ns | ns |
|------------------------------------------------------------+-----------------------------------------------------|
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://www.openmicroscopy.org/ns/default/ | |
| http://www.openmicroscopy.org/ns/default/ | |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://www.openmicroscopy.org/ns/default/ | www.openmicroscopy.org/ns/default |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://hms.harvard.edu/omero/forms/kvdata/MPB_Annotations/ | hms.harvard.edu/omero/forms/kvdata/MPB Annotations/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://www.openmicroscopy.org/ns/default/ | |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://www.openmicroscopy.org/ns/default/ | |
| http://www.openmicroscopy.org/ns/default/ | |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |
| http://purl.org/dc/terms/ | http://purl.org/dc/terms/ |

16 changes: 16 additions & 0 deletions test/test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,22 @@ def test_namespace_fixing_no_ns(self):

self.assertEqual(response_df.iloc[0,0], 'MrX')

def test_namespace_fixing_issue16(self):
""" Test that empty namespaces are set to a default value."""
query = """
PREFIX ome_core: <http://www.openmicroscopy.org/rdf/2016-06/ome_core/>
PREFIX image: <https://example.org/site/Image/>
PREFIX ome_ns: <http://www.openmicroscopy.org/ns/default/>
SELECT DISTINCT * WHERE {
image:10 <http://hms.harvard.edu/omero/forms/kvdata/MPB_Annotations/Assay> ?assay .
}
"""
response_df = run_query(query)

self.assertEqual(response_df.iloc[0,0], 'PRTSC')




if __name__ == "__main__":
Expand Down
8 changes: 6 additions & 2 deletions utils/insert_data.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#! /bin/bash
set -e

source ~/miniconda3/bin/activate

omero login -C -u root -w omero -s localhost:14064

# Create 3 datasets
Expand Down Expand Up @@ -80,6 +78,12 @@ ann=$(omero obj new MapAnnotation ns="www.openmicroscopy.org/ns/default")
omero obj new ImageAnnotationLink parent=Image:11 child=$ann
omero obj map-set $ann mapValue sampletype "screen"

# Add another mapannotation with namespace that is not a valid URI (issue #16).
ann=$(omero obj new MapAnnotation ns="hms.harvard.edu/omero/forms/kvdata/MPB Annotations/")
omero obj new ImageAnnotationLink parent=Image:10 child=$ann
omero obj map-set $ann mapValue Assay "PRTSC"


# List all objects
today=$(date +%Y-%m-%d)
omero search Project --from=$today --to=$today
Expand Down

0 comments on commit 48c95d5

Please sign in to comment.