|
import os |
|
import datasets |
|
from datasets import SplitGenerator, DatasetInfo, GeneratorBasedBuilder |
|
from rdflib import Graph, URIRef, Literal, BNode |
|
from rdflib.namespace import RDF, RDFS, OWL, XSD, DCTERMS, SKOS, DCAM, Namespace |
|
from datasets.features import Features, Value |
|
|
|
class FIBODatasetBuilder(GeneratorBasedBuilder): |
|
VERSION = "1.0.0" |
|
|
|
def _info(self): |
|
return DatasetInfo( |
|
description="The Financial Industry Business Ontology (FIBO) defines the sets of things that are of interest in financial business applications and the ways that those things can relate to one another. In this way, FIBO can give meaning to any data (e.g., spreadsheets, relational databases, XML documents) that describe the business of finance.", |
|
homepage="https://spec.edmcouncil.org/fibo/", |
|
license="MIT", |
|
citation=r"""@misc{fiboQ32023, |
|
title={Financial Industry Business Ontology (FIBO)}, |
|
author={Object Management Group, Inc. and EDM Council, Inc. and Various Contributors}, |
|
year={2023}, |
|
note={Available as OWL 2 ontologies and UML models compliant with the Semantics for Information Modeling and Federation (SMIF) draft specification. Contributions are open on GitHub, consult the repository for a list of contributors.}, |
|
howpublished={\url{https://spec.edmcouncil.org/fibo/}}, |
|
abstract={The Financial Industry Business Ontology (FIBO) is a collaborative effort to standardize the language used to define the terms, conditions, and characteristics of financial instruments; the legal and relationship structure of business entities; the content and time dimensions of market data; and the legal obligations and process aspects of corporate actions.}, |
|
license={MIT License, \url{https://opensource.org/licenses/MIT}} |
|
}""", |
|
features=Features({ |
|
'subject': Value('string'), |
|
'predicate': Value('string'), |
|
'object': Value('string') |
|
}) |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
extracted = dl_manager.download_and_extract("fibo.nt.gz") |
|
|
|
return [SplitGenerator(name=datasets.Split.TRAIN, |
|
gen_kwargs={'filepath': extracted})] |
|
|
|
def _generate_examples(self, filepath): |
|
id_ = 0 |
|
graph = Graph(bind_namespaces="core") |
|
graph.parse(filepath) |
|
|
|
for (s, p, o) in graph.triples((None, None, None)): |
|
yield id_, { |
|
'subject': s.n3(), |
|
'predicate': p.n3(), |
|
'object': o.n3() |
|
} |
|
id_ += 1 |
|
|
|
from rdflib.util import from_n3 |
|
|
|
def triple(features): |
|
try: |
|
subject_node = from_n3(features['subject']) |
|
predicate_node = from_n3(features['predicate']) |
|
object_node = from_n3(features['object']) |
|
return (subject_node, predicate_node, object_node) |
|
except Exception as e: |
|
print(f"Error transforming features {features}: {e}") |
|
return (None, None, None) |
|
|
|
from datasets import load_dataset |
|
|