Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
kwargs.update(kw)
if isinstance(namespace, tuple):
namespace = dict(namespace)
# get the datatypes from configuration as to namespace
datatypes = read_conf(kwargs['conf'])[1]
# Load the dataset.
fname = Path(path)
if not fname.exists():
raise compat.FileNotFoundError(
'{:} does not exist'.format(fname))
if fname.suffix == '.json':
dataset = pycldf.dataset.Dataset.from_metadata(fname)
else:
dataset = pycldf.dataset.Dataset.from_data(fname)
if dataset.module == "Wordlist":
# First, make a list of cognate codes if they are in a separate table.
cognateset_assignments = {}
try:
form_reference = dataset["CognateTable", "formReference"].name
for row in dataset["CognateTable"].iterdicts():
cognateset_assignments[row[form_reference]] = row
except KeyError:
# Either there are no cognate codes, or they are in the form
# table. Both options are fine.
pass
f_id = dataset["FormTable", "id"].name
if isinstance(namespace, tuple):
namespace = dict(namespace)
# get the datatypes from configuration as to namespace
datatypes = read_conf(kwargs['conf'])[1]
# Load the dataset.
fname = Path(path)
if not fname.exists():
raise compat.FileNotFoundError(
'{:} does not exist'.format(fname))
if fname.suffix == '.json':
dataset = pycldf.dataset.Dataset.from_metadata(fname)
else:
dataset = pycldf.dataset.Dataset.from_data(fname)
if dataset.module == "Wordlist":
# First, make a list of cognate codes if they are in a separate table.
cognateset_assignments = {}
try:
form_reference = dataset["CognateTable", "formReference"].name
for row in dataset["CognateTable"].iterdicts():
cognateset_assignments[row[form_reference]] = row
except KeyError:
# Either there are no cognate codes, or they are in the form
# table. Both options are fine.
pass
f_id = dataset["FormTable", "id"].name
# Access columns by type, not by name.
Parameters
----------
fname : str or Path
Path to a CLDF dataset
Returns
-------
Dataset
"""
fname = Path(fname)
if not fname.exists():
raise FileNotFoundError(
'{:} does not exist'.format(fname))
if fname.suffix == '.json':
return pycldf.dataset.Dataset.from_metadata(fname)
return pycldf.dataset.Dataset.from_data(fname)
Parameters
----------
fname : str or Path
Path to a CLDF dataset
Returns
-------
Dataset
"""
fname = Path(fname)
if not fname.exists():
raise FileNotFoundError(
'{:} does not exist'.format(fname))
if fname.suffix == '.json':
return pycldf.dataset.Dataset.from_metadata(fname)
return pycldf.dataset.Dataset.from_data(fname)
def create(self, req, filename=None, verbose=True, outfile=None):
cldf_cfg = req.registry.getUtility(ICldfConfig)
with TemporaryDirectory() as tmpd:
cls = getattr(dataset, cldf_cfg.module)
ds = cls.in_dir(tmpd)
ds.properties['dc:bibliographicCitation'] = text_citation(req, req.dataset)
ds.properties['dc:publisher'] = '%s, %s' % (
req.dataset.publisher_name, req.dataset.publisher_place)
ds.properties['dc:license'] = req.dataset.license
ds.properties['dc:issued'] = req.dataset.published.isoformat()
ds.properties['dc:title'] = req.dataset.name
ds.properties['dc:creator'] = req.dataset.formatted_editors()
ds.properties['dc:identifier'] = req.resource_url(req.dataset)
ds.properties['dcat:accessURL'] = req.route_url('download')
if DBSession.query(Sentence).count():
ds.add_component('ExampleTable')
if DBSession.query(DomainElement).count():
ds.add_component('CodeTable', {'name': 'Number', 'datatype': 'integer'})
ds.add_component('ParameterTable')
ds.add_component('LanguageTable')