mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-04-25 08:26:21 +02:00
Feature/tidy kg load save (#198)
* Clean exit on ctrl-C * More functionality in dump * Dump some metadata
This commit is contained in:
parent
55c5c398b6
commit
fd3db3c925
4 changed files with 177 additions and 37 deletions
|
|
@ -10,7 +10,7 @@ import msgpack
|
|||
import sys
|
||||
import argparse
|
||||
|
||||
def run(input_file):
|
||||
def dump(input_file, action):
|
||||
|
||||
with open(input_file, 'rb') as f:
|
||||
|
||||
|
|
@ -19,6 +19,43 @@ def run(input_file):
|
|||
for unpacked in unpacker:
|
||||
print(unpacked)
|
||||
|
||||
def summary(input_file, action):
|
||||
|
||||
vector_dim = None
|
||||
|
||||
triples = set()
|
||||
|
||||
max_records = 1000000
|
||||
|
||||
with open(input_file, 'rb') as f:
|
||||
|
||||
unpacker = msgpack.Unpacker(f, raw=False)
|
||||
|
||||
rec_count = 0
|
||||
|
||||
for msg in unpacker:
|
||||
|
||||
if msg[0] == "ge":
|
||||
vector_dim = len(msg[1]["v"][0])
|
||||
|
||||
if msg[0] == "t":
|
||||
|
||||
for elt in msg[1]["m"]["m"]:
|
||||
triples.add((
|
||||
elt["s"]["v"],
|
||||
elt["p"]["v"],
|
||||
elt["o"]["v"],
|
||||
))
|
||||
|
||||
if rec_count > max_records: break
|
||||
rec_count += 1
|
||||
|
||||
print("Vector dimension:", vector_dim)
|
||||
|
||||
for t in triples:
|
||||
if t[1] == "http://www.w3.org/2000/01/rdf-schema#label":
|
||||
print("-", t[2])
|
||||
|
||||
def main():
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
|
|
@ -32,9 +69,24 @@ def main():
|
|||
help=f'Input file'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-s', '--summary', action="store_const", const="summary",
|
||||
dest="action",
|
||||
help=f'Show a summary'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'-r', '--records', action="store_const", const="records",
|
||||
dest="action",
|
||||
help=f'Dump individual records'
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
run(**vars(args))
|
||||
if args.action == "summary":
|
||||
summary(**vars(args))
|
||||
else:
|
||||
dump(**vars(args))
|
||||
|
||||
main()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue