Commit
·
d264ba2
1
Parent(s):
4e9cef7
category replaced by data_source_name
Browse files
kg_builder/src/graph_creation.py
CHANGED
|
@@ -16,11 +16,11 @@ articles = {
|
|
| 16 |
"Traffic Law": "Traffic laws in the United States"
|
| 17 |
}
|
| 18 |
|
| 19 |
-
def build_graph_for_article(query,
|
| 20 |
"""
|
| 21 |
Build knowledge graph from loaded articles / documents of a particular topic
|
| 22 |
:param query: The query string to search on Wikipedia, e.g. "Traffic laws in the United States"
|
| 23 |
-
:param
|
| 24 |
:return:
|
| 25 |
"""
|
| 26 |
load_max_documents = 5
|
|
@@ -49,11 +49,11 @@ def build_graph_for_article(query, category):
|
|
| 49 |
for i, chunkDoc in tqdm(enumerate(chunkDocs), total=len(chunkDocs)):
|
| 50 |
print(f"Extract data from chunk {str(i)} ...")
|
| 51 |
#print(f"Extract data from chunk {str(i)}: {chunkDoc.page_content}")
|
| 52 |
-
extract_and_store_graph(chunkDoc,
|
| 53 |
|
| 54 |
def main():
|
| 55 |
-
for
|
| 56 |
-
build_graph_for_article(
|
| 57 |
|
| 58 |
if __name__ == "__main__":
|
| 59 |
main()
|
|
|
|
| 16 |
"Traffic Law": "Traffic laws in the United States"
|
| 17 |
}
|
| 18 |
|
| 19 |
+
def build_graph_for_article(query, data_source_name):
|
| 20 |
"""
|
| 21 |
Build knowledge graph from loaded articles / documents of a particular topic
|
| 22 |
:param query: The query string to search on Wikipedia, e.g. "Traffic laws in the United States"
|
| 23 |
+
:param data_source_name: Data source name, e.g. "Traffic Law"
|
| 24 |
:return:
|
| 25 |
"""
|
| 26 |
load_max_documents = 5
|
|
|
|
| 49 |
for i, chunkDoc in tqdm(enumerate(chunkDocs), total=len(chunkDocs)):
|
| 50 |
print(f"Extract data from chunk {str(i)} ...")
|
| 51 |
#print(f"Extract data from chunk {str(i)}: {chunkDoc.page_content}")
|
| 52 |
+
extract_and_store_graph(chunkDoc, data_source_name)
|
| 53 |
|
| 54 |
def main():
|
| 55 |
+
for data_source_name, query in articles.items():
|
| 56 |
+
build_graph_for_article(query, data_source_name)
|
| 57 |
|
| 58 |
if __name__ == "__main__":
|
| 59 |
main()
|