def test_updated_dump(self): with gzip.open(resource_filename(__name__, "Wikidata-Q15511.json.gz"), "r") as f: result = list(JsonReader.read_json(f)) self.assertThat(result, HasLength(1)) q15511 = result[0] self.assertThat(q15511.title, Equals("Q15511")) self.assertThat(q15511.claims, Contains(Claim(Snak(1082, "quantity", "+25"), [Snak(585, "time", "+00000002001-01-01T00:00:00Z"), Snak(459, "wikibase-item", "Q745221")], [Snak(248, "wikibase-item", "Q17597573")])))
def test_updated_dump(self): file_name = resource_filename(__name__, "Wikidata-Q15511.json.gz") with gzip.open(file_name, 'r') as f: result = list(JsonReader.read_json(f)) claim = Claim(Snak(1082, "quantity", "+25"), [ Snak(459, "wikibase-item", "Q745221"), Snak(585, "time", "+2001-01-01T00:00:00Z") ], [Snak(248, "wikibase-item", "Q17597573")]) assert 1 == len(result) q15511 = result[0] assert 'Q15511' == q15511.title assert claim in q15511.claims
import logging import argparse import sys import time from propertysuggester.parser import JsonReader, CsvWriter from propertysuggester.utils.CompressedFileType import CompressedFileType if __name__ == "__main__": logging.basicConfig(level=20) # Print logging.info parser = argparse.ArgumentParser( description="this program converts wikidata JSON dumps to CSV data.") parser.add_argument("input", help="The JSON input file (a wikidata dump)", type=CompressedFileType('r')) parser.add_argument("output", help="The CSV output file (default=sys.stdout)", default=sys.stdout, nargs='?', type=CompressedFileType('wb')) args = parser.parse_args() start = time.time() CsvWriter.write_csv(JsonReader.read_json(args.input), args.output) logging.info("total time: %.2fs" % (time.time() - start))
def test_special_cases(self): data = dict([("id", "Q1"), ("type", "item")]) assert Entity("Q1", []) == JsonReader._process_json(data)
def test_special_cases(self): data = dict([("id", "Q1"), ("type", "item")]) self.assertThat(JsonReader._process_json(data), Equals(Entity("Q1", [])))