Skip to content

Commit

Permalink
Merge pull request #424 from mboudet/dev
Browse files Browse the repository at this point in the history
Rewrite ontology management + some stuff
  • Loading branch information
mboudet authored Oct 31, 2023
2 parents f36a977 + bc61f58 commit 4569fd5
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 136 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

This changelog was started for release 4.2.0.

## [4.6.0] - Unreleased

### Added

- "askomics:instancesLabel" predicate can be defined at the entity-level, to set a specific attribute URI as the 'label' (ie, visible by default)
- Play the same role as 'askomics:instancesHaveNoLabels', except a specific attribute is visible instead of the URI attribute.
- Added the *TIMEOUT* env variable, which will set the web workers tiemout value. Default 300s

### Changed

- Rewrote the ontology part. Instead of specifying 'children of' and other values, users can tick the 'recursive' button to customize the query. While this is less intuitive, this change is more flexible for the various types of ontological relations

## [4.5.0] - 2023-10-20

### **Deprecation warning**
Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ PYTESTOPTS=
TESTFILE?=tests
NTASKS?=1
WORKERS?=1
TIMEOUT?=300

HOST?=0.0.0.0
PORT?=5000
Expand Down Expand Up @@ -107,7 +108,7 @@ serve-askomics: check-venv build-config create-user
ifeq ($(MODE), dev)
FLASK_ENV=development FLASK_APP=app flask run --host=$(HOST) --port $(PORT)
else
FLASK_ENV=production FLASK_APP=app gunicorn -w $(WORKERS) -b $(HOST):$(PORT) app
FLASK_ENV=production FLASK_APP=app gunicorn --timeout $(TIMEOUT) -w $(WORKERS) -b $(HOST):$(PORT) app
endif

serve-celery: check-venv build-config create-user
Expand Down
2 changes: 2 additions & 0 deletions askomics/libaskomics/FilesHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ def get_type(self, file_ext):
return 'rdf/xml'
elif file_ext in ('.nt', ):
return 'rdf/nt'
elif file_ext in ('.owl', ):
return 'rdf/xml'
# Default is csv
return 'csv/tsv'

Expand Down
14 changes: 7 additions & 7 deletions askomics/libaskomics/SparqlQuery.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,19 +1362,19 @@ def build_query_from_json(self, preview=False, for_editor=False):
# Classic relation
else:
# Manage ontology stuff
is_inverse = link.get("reverse", False)
inverse = ""
recurrence = ""
is_recursive = link.get("recursive", False)
recursive = ""
relation = link["uri"]

if relation.startswith("^"):
if is_inverse:
inverse = "^"
relation = relation.lstrip("^")

if relation.endswith("*"):
recurrence = "*"
relation = relation.rstrip("*")
if is_recursive:
recursive = "*"

relation = inverse + "<{}>".format(relation) + recurrence
relation = inverse + "<{}>".format(relation) + recursive
triple = {
"subject": source,
"predicate": relation,
Expand Down
10 changes: 7 additions & 3 deletions askomics/libaskomics/TriplestoreExplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ def get_abstraction_entities(self, single_tenant=False):
query_builder = SparqlQuery(self.app, self.session)

query = '''
SELECT DISTINCT ?endpoint ?graph ?entity_uri ?entity_type ?entity_faldo ?entity_label ?have_no_label
SELECT DISTINCT ?endpoint ?graph ?entity_uri ?entity_type ?entity_faldo ?entity_label ?have_no_label ?default_visible
WHERE {{
?graph askomics:public ?public .
?graph dc:creator ?creator .
Expand All @@ -339,6 +339,7 @@ def get_abstraction_entities(self, single_tenant=False):
# Label
OPTIONAL {{ ?entity_uri rdfs:label ?entity_label . }}
OPTIONAL {{ ?entity_uri askomics:instancesHaveNoLabels ?have_no_label . }}
OPTIONAL {{ ?entity_uri askomics:instancesLabel ?default_visible . }}
}}
FILTER (
?public = <true>{}
Expand Down Expand Up @@ -367,6 +368,7 @@ def get_abstraction_entities(self, single_tenant=False):
"ontology": True if result["entity_type"] == "{}ontology".format(self.settings.get("triplestore", "namespace_internal")) else False,
"endpoints": [result["endpoint"]],
"graphs": [result["graph"]],
"defaultVisible": result.get("default_visible")
}

entities.append(entity)
Expand Down Expand Up @@ -519,7 +521,7 @@ def get_abstraction_relations(self, single_tenant=False):
query_builder = SparqlQuery(self.app, self.session)

query = '''
SELECT DISTINCT ?graph ?entity_uri ?entity_faldo ?entity_label ?attribute_uri ?attribute_faldo ?attribute_label ?attribute_range ?property_uri ?property_faldo ?property_label ?range_uri ?category_value_uri ?category_value_label ?indirect_relation
SELECT DISTINCT ?graph ?entity_uri ?entity_faldo ?entity_label ?attribute_uri ?attribute_faldo ?attribute_label ?attribute_range ?property_uri ?property_faldo ?property_label ?range_uri ?category_value_uri ?category_value_label ?indirect_relation ?is_recursive
WHERE {{
# Graphs
?graph askomics:public ?public .
Expand All @@ -534,6 +536,7 @@ def get_abstraction_relations(self, single_tenant=False):
# Retrocompatibility
OPTIONAL {{?node askomics:uri ?new_property_uri}}
BIND( IF(isBlank(?node), ?new_property_uri, ?node) as ?property_uri)
OPTIONAL {{?node askomics:isRecursive ?is_recursive}}
}}
# Relation of entity (or motherclass of entity)
{{
Expand Down Expand Up @@ -565,7 +568,8 @@ def get_abstraction_relations(self, single_tenant=False):
"graphs": [result["graph"], ],
"source": result["entity_uri"],
"target": result["range_uri"],
"indirect": result.get("indirect_relation", False)
"indirect": result.get("indirect_relation", False),
"recursive": result.get("is_recursive", False),
}
relations.append(relation)
else:
Expand Down
38 changes: 3 additions & 35 deletions askomics/react/src/routes/query/ontolinkview.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,16 @@ import PropTypes from 'prop-types'
export default class OntoLinkView extends Component {
constructor (props) {
super(props)
this.handleChangeOntologyType = this.props.handleChangeOntologyType.bind(this)
this.handleRecursiveOntology = this.props.handleRecursiveOntology.bind(this)
}


render () {

let content = (
<>
<option selected={this.props.link.uri == 'http://www.w3.org/2000/01/rdf-schema#subClassOf' ? true : false} value="http://www.w3.org/2000/01/rdf-schema#subClassOf">children of</option>
<option selected={this.props.link.uri == 'http://www.w3.org/2000/01/rdf-schema#subClassOf*' ? true : false} value="http://www.w3.org/2000/01/rdf-schema#subClassOf*">descendants of</option>
<option selected={this.props.link.uri == '^http://www.w3.org/2000/01/rdf-schema#subClassOf' ? true : false} value="^http://www.w3.org/2000/01/rdf-schema#subClassOf">parents of</option>
<option selected={this.props.link.uri == '^http://www.w3.org/2000/01/rdf-schema#subClassOf*' ? true : false} value="^http://www.w3.org/2000/01/rdf-schema#subClassOf*">ancestors of</option>
</>
)

if (this.props.link.uri.includes("http://www.w3.org/2004/02/skos/core")){
content = (
<>
<option selected={this.props.link.uri == 'http://www.w3.org/2004/02/skos/core#broader' ? true : false} value="http://www.w3.org/2004/02/skos/core#broader">children of</option>
<option selected={this.props.link.uri == 'http://www.w3.org/2004/02/skos/core#broader*' ? true : false} value="http://www.w3.org/2004/02/skos/core#broader*">descendants of</option>
<option selected={this.props.link.uri == 'http://www.w3.org/2004/02/skos/core#narrower' ? true : false} value="http://www.w3.org/2004/02/skos/core#narrower">parents of</option>
<option selected={this.props.link.uri == 'http://www.w3.org/2004/02/skos/core#narrower*' ? true : false} value="http://www.w3.org/2004/02/skos/core#narrower*">ancestors of</option>
</>
)
}


return (
<div className="container">
<h5>Ontological Relation</h5>
<hr />
<p>Search on ...</p>
<table>
<tr>
<td>
<CustomInput type="select" id={this.props.link.id} name="ontology_position" onChange={this.handleChangeOntologyType}>
{content}
</CustomInput>
</td>
<td>&nbsp;a term</td>
</tr>
</table>
<CustomInput disabled={!this.props.link.isRecursive} onChange={this.handleRecursiveOntology} checked={this.props.link.recursive ? true : false} value={this.props.link.recursive ? true : false} type="checkbox" id={this.props.link.id} label="Recursive" />
<br />
</div>
)
Expand All @@ -61,5 +29,5 @@ export default class OntoLinkView extends Component {

OntoLinkView.propTypes = {
link: PropTypes.object,
handleChangeOntologyType: PropTypes.func,
handleRecursiveOntology: PropTypes.func
}
Loading

0 comments on commit 4569fd5

Please sign in to comment.