Skip to content

Commit

Permalink
Use numbers.Real in place of float in fields where openMINDS specifie…
Browse files Browse the repository at this point in the history
…s type "number" (fixes #60)
  • Loading branch information
apdavison committed Nov 19, 2024
1 parent 8158639 commit 3e6c8b6
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 12 deletions.
3 changes: 2 additions & 1 deletion builder/update_openminds.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ def get_controlled_terms_table(type_):
preamble = {
"File": """import os
import mimetypes
from numbers import Real
from pathlib import Path
from urllib.request import urlretrieve
from urllib.parse import quote, urlparse, urlunparse
Expand Down Expand Up @@ -612,7 +613,7 @@ def get_type(prop):
type_map = {
"string": "str",
"integer": "int",
"number": "float",
"number": "Real",
"date": "date",
"date-time": "datetime",
"time": "time",
Expand Down
3 changes: 2 additions & 1 deletion fairgraph/openminds/computation/model_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@


from datetime import datetime, time
from numbers import Real


class ModelValidation(KGObject):
Expand Down Expand Up @@ -94,7 +95,7 @@ class ModelValidation(KGObject):
multiple=True,
doc="no description available",
),
Property("score", float, "vocab:score", doc="no description available"),
Property("score", Real, "vocab:score", doc="no description available"),
Property("start_time", [datetime, time], "vocab:startTime", required=True, doc="no description available"),
Property(
"started_by",
Expand Down
6 changes: 4 additions & 2 deletions fairgraph/openminds/core/miscellaneous/quantitative_value.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from fairgraph import EmbeddedMetadata, IRI
from fairgraph.properties import Property

from numbers import Real


class QuantitativeValue(EmbeddedMetadata):
"""
Expand All @@ -30,7 +32,7 @@ class QuantitativeValue(EmbeddedMetadata):
),
Property(
"uncertainties",
float,
Real,
"vocab:uncertainty",
multiple=True,
doc="Quantitative value range defining the uncertainty of a measurement.",
Expand All @@ -41,7 +43,7 @@ class QuantitativeValue(EmbeddedMetadata):
"vocab:unit",
doc="Determinate quantity adopted as a standard of measurement.",
),
Property("value", float, "vocab:value", required=True, doc="Entry for a property."),
Property("value", Real, "vocab:value", required=True, doc="Entry for a property."),
]
reverse_properties = []

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from fairgraph import KGObject, IRI
from fairgraph.properties import Property

from numbers import Real


class QuantitativeValueArray(KGObject):
"""
Expand All @@ -25,14 +27,14 @@ class QuantitativeValueArray(KGObject):
properties = [
Property(
"negative_uncertainties",
float,
Real,
"vocab:negativeUncertainties",
multiple=True,
doc="no description available",
),
Property(
"positive_uncertainties",
float,
Real,
"vocab:positiveUncertainties",
multiple=True,
doc="no description available",
Expand All @@ -49,7 +51,7 @@ class QuantitativeValueArray(KGObject):
"vocab:unit",
doc="Determinate quantity adopted as a standard of measurement.",
),
Property("values", float, "vocab:values", multiple=True, required=True, doc="no description available"),
Property("values", Real, "vocab:values", multiple=True, required=True, doc="no description available"),
]
reverse_properties = []
existence_query_properties = ("values",)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from fairgraph import EmbeddedMetadata, IRI
from fairgraph.properties import Property

from numbers import Real


class QuantitativeValueRange(EmbeddedMetadata):
"""
Expand All @@ -22,14 +24,14 @@ class QuantitativeValueRange(EmbeddedMetadata):
"core": "https://openminds.ebrains.eu/core/",
}
properties = [
Property("max_value", float, "vocab:maxValue", required=True, doc="Greatest quantity attained or allowed."),
Property("max_value", Real, "vocab:maxValue", required=True, doc="Greatest quantity attained or allowed."),
Property(
"max_value_unit",
"openminds.controlled_terms.UnitOfMeasurement",
"vocab:maxValueUnit",
doc="no description available",
),
Property("min_value", float, "vocab:minValue", required=True, doc="Smallest quantity attained or allowed."),
Property("min_value", Real, "vocab:minValue", required=True, doc="Smallest quantity attained or allowed."),
Property(
"min_value_unit",
"openminds.controlled_terms.UnitOfMeasurement",
Expand Down
5 changes: 3 additions & 2 deletions fairgraph/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from __future__ import annotations
import logging
import numbers
from datetime import date, datetime
from collections.abc import Iterable, Mapping
from typing import Any, Dict, List, Optional, Tuple, TYPE_CHECKING, Union
Expand Down Expand Up @@ -249,7 +250,7 @@ def serialize(self, value: Any, follow_links: bool = False):
"""

def serialize_single(value):
if isinstance(value, (str, int, float, dict)):
if isinstance(value, (str, numbers.Real, dict)):
return value
elif isinstance(value, EmbeddedMetadata):
return value.to_jsonld(follow_links=follow_links)
Expand Down Expand Up @@ -457,7 +458,7 @@ def get_query_filter_property(self, filter: Any) -> QueryProperty:
filter_obj = None
else:
# we have a filter value for this property
if self.types[0] in (int, float, bool, datetime, date):
if self.types[0] in (int, float, numbers.Real, bool, datetime, date):
op = "EQUALS"
else:
op = "CONTAINS"
Expand Down
3 changes: 2 additions & 1 deletion test/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

from datetime import date, datetime
from numbers import Real
from fairgraph.embedded import EmbeddedMetadata
from fairgraph.kgobject import KGObject
from fairgraph.kgproxy import KGProxy
Expand Down Expand Up @@ -37,7 +38,7 @@ class MockEmbeddedObject(EmbeddedMetadata):
),
Property(
"a_number",
float,
Real,
"https://openminds.ebrains.eu/vocab/aNumber",
multiple=False,
required=True,
Expand Down

0 comments on commit 3e6c8b6

Please sign in to comment.