wikipunk commited on
Commit
4eca7c8
1 Parent(s): e0dd3d8

use GeneratorBasedBuilder as superclass

Browse files
Files changed (1) hide show
  1. yago45en.py +12 -11
yago45en.py CHANGED
@@ -1,5 +1,6 @@
1
  import os
2
- from datasets import DatasetBuilder, SplitGenerator, DownloadConfig, load_dataset, DownloadManager, DatasetInfo
 
3
  from rdflib import Graph, URIRef, Literal, BNode
4
  from rdflib.namespace import RDF, RDFS, OWL, XSD, Namespace, NamespaceManager
5
  from datasets.features import Features, Value
@@ -8,13 +9,12 @@ SCHEMA = Namespace('http://schema.org/')
8
 
9
  YAGO = Namespace('http://yago-knowledge.org/resource/')
10
 
11
- class YAGO45DatasetBuilder(DatasetBuilder):
12
  VERSION = "1.0.0"
13
 
14
  taxonomy = Graph(bind_namespaces="core")
15
 
16
  def _info(self):
17
- print("INFO")
18
  return DatasetInfo(
19
  description="A subset of the YAGO 4.5 dataset maintaining only English labels",
20
  citation="@article{suchanek2023integrating,title={Integrating the Wikidata Taxonomy into YAGO},author={Suchanek, Fabian M and Alam, Mehwish and Bonald, Thomas and Paris, Pierre-Henri and Soria, Jules},journal={arXiv preprint arXiv:2308.11884},year={2023}}",
@@ -32,18 +32,21 @@ class YAGO45DatasetBuilder(DatasetBuilder):
32
  # Define splits for each chunk of your dataset.
33
 
34
  # Download and extract the dataset files
35
- dl_manager.download_config = DownloadConfig(cache_dir=os.path.abspath("raw"))
36
- dl_manager.download_and_extract(["facts.tar.gz", "yago-taxonomy.ttl"])
37
-
 
38
  # Load yago-taxonomy.ttl file in every process
39
- self.taxonomy.parse(os.path.join(dl_manager.manual_dir, 'yago-taxonomy.ttl'), format='turtle')
40
 
41
  # Extract prefix mappings
42
  prefix_mappings = {prefix: namespace for prefix, namespace in self.taxonomy.namespaces()}
43
 
44
  # Define splits for each chunk
45
- chunk_paths = [os.path.join(dl_manager.manual_dir, chunk) for chunk in os.listdir(dl_manager.manual_dir) if chunk.endswith('.nt')]
46
- return [SplitGenerator(name="train", gen_kwargs={'chunk_paths': chunk_paths, 'prefix_mappings': prefix_mappings})]
 
 
47
 
48
  def _generate_examples(self, chunk_paths, prefix_mappings):
49
  # Load the chunks into an rdflib graph
@@ -61,5 +64,3 @@ class YAGO45DatasetBuilder(DatasetBuilder):
61
  'predicate': str(p),
62
  'object': str(o)
63
  }
64
-
65
-
 
1
  import os
2
+ import datasets
3
+ from datasets import DatasetBuilder, SplitGenerator, DownloadConfig, load_dataset, DownloadManager, DatasetInfo, GeneratorBasedBuilder
4
  from rdflib import Graph, URIRef, Literal, BNode
5
  from rdflib.namespace import RDF, RDFS, OWL, XSD, Namespace, NamespaceManager
6
  from datasets.features import Features, Value
 
9
 
10
  YAGO = Namespace('http://yago-knowledge.org/resource/')
11
 
12
+ class YAGO45DatasetBuilder(GeneratorBasedBuilder):
13
  VERSION = "1.0.0"
14
 
15
  taxonomy = Graph(bind_namespaces="core")
16
 
17
  def _info(self):
 
18
  return DatasetInfo(
19
  description="A subset of the YAGO 4.5 dataset maintaining only English labels",
20
  citation="@article{suchanek2023integrating,title={Integrating the Wikidata Taxonomy into YAGO},author={Suchanek, Fabian M and Alam, Mehwish and Bonald, Thomas and Paris, Pierre-Henri and Soria, Jules},journal={arXiv preprint arXiv:2308.11884},year={2023}}",
 
32
  # Define splits for each chunk of your dataset.
33
 
34
  # Download and extract the dataset files
35
+ facts, taxonomy = dl_manager.download_and_extract(["facts.tar.gz", "yago-taxonomy.ttl"])
36
+
37
+ facts = os.path.join(facts, "tmp/yago/")
38
+
39
  # Load yago-taxonomy.ttl file in every process
40
+ self.taxonomy.parse(taxonomy)
41
 
42
  # Extract prefix mappings
43
  prefix_mappings = {prefix: namespace for prefix, namespace in self.taxonomy.namespaces()}
44
 
45
  # Define splits for each chunk
46
+ chunk_paths = [os.path.join(facts, chunk) for chunk in os.listdir(facts) if chunk.endswith('.nt')]
47
+ return [SplitGenerator(name=datasets.Split.TRAIN,
48
+ gen_kwargs={'chunk_paths': chunk_paths,
49
+ 'prefix_mappings': prefix_mappings})]
50
 
51
  def _generate_examples(self, chunk_paths, prefix_mappings):
52
  # Load the chunks into an rdflib graph
 
64
  'predicate': str(p),
65
  'object': str(o)
66
  }