Skip to content

Commit

Permalink
Comment out owl related code pending new version
Browse files Browse the repository at this point in the history
  • Loading branch information
IanCa committed Mar 20, 2024
1 parent a74eb54 commit c93eb00
Show file tree
Hide file tree
Showing 6 changed files with 779 additions and 784 deletions.
94 changes: 47 additions & 47 deletions hed/schema/hed_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from hed.schema.schema_io import schema_util
from hed.schema.schema_io.schema2xml import Schema2XML
from hed.schema.schema_io.schema2wiki import Schema2Wiki
from hed.schema.schema_io.schema2owl import Schema2Owl
from hed.schema.schema_io.owl_constants import ext_to_format
# from hed.schema.schema_io.schema2owl import Schema2Owl
# from hed.schema.schema_io.owl_constants import ext_to_format
from hed.schema.hed_schema_section import (HedSchemaSection, HedSchemaTagSection, HedSchemaUnitClassSection,
HedSchemaUnitSection)
from hed.errors import ErrorHandler
Expand Down Expand Up @@ -246,25 +246,25 @@ def get_as_mediawiki_string(self, save_merged=False):
output_strings = Schema2Wiki.process_schema(self, save_merged)
return '\n'.join(output_strings)

def get_as_owl_string(self, save_merged=False, file_format="owl"):
""" Return the schema to a mediawiki string.
Parameters:
save_merged (bool): If True, this will save the schema as a merged schema if it is a "withStandard" schema.
If it is not a "withStandard" schema, this setting has no effect.
file_format(str or None): Override format from filename extension.
Accepts any value rdflib accepts(We fully support "turtle", "xml"("owl" also accepted) and "json-ld").
Other values should work, but aren't as fully supported.
Returns:
str: The schema as a string in mediawiki format.
:raises rdflib.plugin.PluginException:
- Invalid format of file_format. Make sure you use a supported RDF format.
"""
if file_format == "owl":
file_format = "xml"
rdf_data = Schema2Owl.process_schema(self, save_merged)
return rdf_data.serialize(format=file_format)
# def get_as_owl_string(self, save_merged=False, file_format="owl"):
# """ Return the schema to a mediawiki string.
#
# Parameters:
# save_merged (bool): If True, this will save the schema as a merged schema if it is a "withStandard" schema.
# If it is not a "withStandard" schema, this setting has no effect.
# file_format(str or None): Override format from filename extension.
# Accepts any value rdflib accepts(We fully support "turtle", "xml"("owl" also accepted) and "json-ld").
# Other values should work, but aren't as fully supported.
# Returns:
# str: The schema as a string in mediawiki format.
#
# :raises rdflib.plugin.PluginException:
# - Invalid format of file_format. Make sure you use a supported RDF format.
# """
# if file_format == "owl":
# file_format = "xml"
# rdf_data = Schema2Owl.process_schema(self, save_merged)
# return rdf_data.serialize(format=file_format)

def get_as_xml_string(self, save_merged=True):
""" Return the schema to an XML string.
Expand Down Expand Up @@ -298,32 +298,32 @@ def save_as_mediawiki(self, filename, save_merged=False):
opened_file.write(string)
opened_file.write('\n')

def save_as_owl(self, filename, save_merged=False, file_format=None):
""" Save as json to a file.
filename: str
Save the file here
save_merged: bool
If True, this will save the schema as a merged schema if it is a "withStandard" schema.
If it is not a "withStandard" schema, this setting has no effect.
file_format(str or None): Required for owl formatted files other than the following:
.ttl: turtle
.owl: xml
.json-ld: json-ld
:raises OSError:
- File cannot be saved for some reason
:raises rdflib.plugin.PluginException:
- Invalid format of file_format. Make sure you use a supported RDF format.
"""
ext = os.path.splitext(filename.lower())[1]
if ext in ext_to_format and file_format is None:
file_format = ext_to_format[ext]
if file_format == "owl":
file_format = "xml"
rdf_data = Schema2Owl.process_schema(self, save_merged)
rdf_data.serialize(filename, format=file_format)
# def save_as_owl(self, filename, save_merged=False, file_format=None):
# """ Save as json to a file.
#
# filename: str
# Save the file here
# save_merged: bool
# If True, this will save the schema as a merged schema if it is a "withStandard" schema.
# If it is not a "withStandard" schema, this setting has no effect.
# file_format(str or None): Required for owl formatted files other than the following:
# .ttl: turtle
# .owl: xml
# .json-ld: json-ld
#
# :raises OSError:
# - File cannot be saved for some reason
#
# :raises rdflib.plugin.PluginException:
# - Invalid format of file_format. Make sure you use a supported RDF format.
# """
# ext = os.path.splitext(filename.lower())[1]
# if ext in ext_to_format and file_format is None:
# file_format = ext_to_format[ext]
# if file_format == "owl":
# file_format = "xml"
# rdf_data = Schema2Owl.process_schema(self, save_merged)
# rdf_data.serialize(filename, format=file_format)

def save_as_xml(self, filename, save_merged=True):
""" Save as XML to a file.
Expand Down
25 changes: 10 additions & 15 deletions hed/schema/hed_schema_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

from hed.schema.schema_io.xml2schema import SchemaLoaderXML
from hed.schema.schema_io.wiki2schema import SchemaLoaderWiki
from hed.schema.schema_io.owl2schema import SchemaLoaderOWL
# from hed.schema.schema_io.owl2schema import SchemaLoaderOWL
from hed.schema import hed_cache

from hed.errors.exceptions import HedFileError, HedExceptions
from hed.schema.schema_io import schema_util
from hed.schema.hed_schema_group import HedSchemaGroup
from hed.schema.schema_validation_util import validate_version_string
from collections import defaultdict
from hed.schema.schema_io.owl_constants import ext_to_format
# from hed.schema.schema_io.owl_constants import ext_to_format
from urllib.error import URLError

MAX_MEMORY_CACHE = 40
Expand All @@ -26,7 +26,6 @@ def from_string(schema_string, schema_format=".xml", schema_namespace=None, sche
schema_string (str): An XML, mediawiki or OWL, file as a single long string
schema_format (str): The schema format of the source schema string.
Allowed normal values: .mediawiki, .xml
Allowed owl values: xml, owl, pretty-xml, turtle (or any other value rdflib supports)
schema_namespace (str, None): The name_prefix all tags in this schema will accept.
schema(HedSchema or None): A hed schema to merge this new file into
It must be a with-standard schema with the same value.
Expand Down Expand Up @@ -54,9 +53,9 @@ def from_string(schema_string, schema_format=".xml", schema_namespace=None, sche
hed_schema = SchemaLoaderXML.load(schema_as_string=schema_string, schema=schema, name=name)
elif schema_format.endswith(".mediawiki"):
hed_schema = SchemaLoaderWiki.load(schema_as_string=schema_string, schema=schema, name=name)
elif schema_format:
hed_schema = SchemaLoaderOWL.load(schema_as_string=schema_string, schema=schema, file_format=schema_format,
name=name)
# elif schema_format:
# hed_schema = SchemaLoaderOWL.load(schema_as_string=schema_string, schema=schema, file_format=schema_format,
# name=name)
else:
raise HedFileError(HedExceptions.INVALID_EXTENSION, f"Unknown schema extension {schema_format}", filename=name)

Expand All @@ -65,18 +64,14 @@ def from_string(schema_string, schema_format=".xml", schema_namespace=None, sche
return hed_schema


def load_schema(hed_path, schema_namespace=None, schema=None, file_format=None, name=None):
def load_schema(hed_path, schema_namespace=None, schema=None, name=None):
""" Load a schema from the given file or URL path.
Parameters:
hed_path (str): A filepath or url to open a schema from.
schema_namespace (str or None): The name_prefix all tags in this schema will accept.
schema(HedSchema or None): A hed schema to merge this new file into
It must be a with-standard schema with the same value.
file_format(str or None): Required for owl formatted files other than the following:
.ttl: turtle
.owl: xml
.json-ld: json-ld
name(str or None): User supplied identifier for this schema
Returns:
Expand All @@ -100,10 +95,10 @@ def load_schema(hed_path, schema_namespace=None, schema=None, file_format=None,
except URLError as e:
raise HedFileError(HedExceptions.URL_ERROR, str(e), hed_path) from e
hed_schema = from_string(file_as_string, schema_format=os.path.splitext(hed_path.lower())[1], name=name)
elif ext in ext_to_format:
hed_schema = SchemaLoaderOWL.load(hed_path, schema=schema, file_format=ext_to_format[ext], name=name)
elif file_format:
hed_schema = SchemaLoaderOWL.load(hed_path, schema=schema, file_format=file_format, name=name)
# elif ext in ext_to_format:
# hed_schema = SchemaLoaderOWL.load(hed_path, schema=schema, file_format=ext_to_format[ext], name=name)
# elif file_format:
# hed_schema = SchemaLoaderOWL.load(hed_path, schema=schema, file_format=file_format, name=name)
elif hed_path.lower().endswith(".xml"):
hed_schema = SchemaLoaderXML.load(hed_path, schema=schema, name=name)
elif hed_path.lower().endswith(".mediawiki"):
Expand Down
Loading

0 comments on commit c93eb00

Please sign in to comment.