forked from AzureCosmosDB/CosmosAIGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_hotpot.py
67 lines (54 loc) · 1.74 KB
/
main_hotpot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
"""
This program is experimental, for AI-based graph generation of the HotPotQA dataset.
See file private/common_data/HotPotQA/combined_ontology.ttl in this repo.
Usage:
python main_hotpot.py read_combined_ontology
Options:
-h --help Show this screen.
--version Show version.
"""
import json
import logging
import os
import sys
import textwrap
import time
from docopt import docopt
from dotenv import load_dotenv
import rdflib
from rdflib import Graph, Literal, RDF, URIRef
from rdflib.namespace import Namespace
from src.services.config_service import ConfigService
from src.services.logging_level_service import LoggingLevelService
from src.util.fs import FS
logging.basicConfig(
format="%(asctime)s - %(message)s", level=LoggingLevelService.get_level()
)
def print_options(msg):
print(msg)
arguments = docopt(__doc__, version="1.0.0")
print(arguments)
def read_combined_ontology():
graph_namespace = "http://example.org/ontology#"
graph_namespace_alias = "ontology"
CNS = Namespace(graph_namespace)
ontology_file = "../private/common_data/HotPotQA/combined_ontology_edited.ttl"
g = Graph()
g.bind(graph_namespace_alias, CNS)
g.parse(ontology_file, format="ttl")
print(g)
if __name__ == "__main__":
load_dotenv(override=True)
if len(sys.argv) < 2:
print_options("Error: invalid command-line")
exit(1)
else:
try:
func = sys.argv[1].lower()
if func == "read_combined_ontology":
read_combined_ontology()
else:
print_options("Error: invalid function: {}".format(func))
except Exception as e:
logging.critical(str(e))
logging.exception(e, stack_info=True, exc_info=True)