Spaces:
Sleeping
Sleeping
Ludovic Moncla
commited on
Commit
·
75c3e68
1
Parent(s):
f62db81
Update utils.py
Browse files
utils.py
CHANGED
|
@@ -105,7 +105,7 @@ def identifier_cardinal(text):
|
|
| 105 |
|
| 106 |
return None
|
| 107 |
|
| 108 |
-
def link_to_subject_object(g, head_type, head_uri, relation_type, relation_word, prev_span, next_span, statement_uris,
|
| 109 |
|
| 110 |
relation_triplets = {}
|
| 111 |
with open('./assets/reference_triplet_relation.csv', mode='r', encoding='utf-8') as f:
|
|
@@ -126,7 +126,7 @@ def link_to_subject_object(g, head_type, head_uri, relation_type, relation_word,
|
|
| 126 |
|
| 127 |
# cas où le prédicat est une distance ou une orientation
|
| 128 |
if relation_type != "Distance-Orientation":
|
| 129 |
-
stmt_uri =
|
| 130 |
|
| 131 |
if relation_word.lower() in statement_uris:
|
| 132 |
key = relation_word.lower() + str(len(statement_uris))
|
|
@@ -134,35 +134,35 @@ def link_to_subject_object(g, head_type, head_uri, relation_type, relation_word,
|
|
| 134 |
key = relation_word.lower()
|
| 135 |
|
| 136 |
statement_uris[key] = stmt_uri
|
| 137 |
-
add_triplet(g, stmt_uri, RDF.subject,
|
| 138 |
-
add_triplet(g, stmt_uri, RDF.object,
|
| 139 |
-
add_triplet(g, stmt_uri, RDF.predicate,
|
| 140 |
else:
|
| 141 |
cardinal = identifier_cardinal(relation_word)
|
| 142 |
distance = identifier_distance(relation_word)
|
| 143 |
|
| 144 |
if cardinal:
|
| 145 |
-
stmt_uri =
|
| 146 |
if relation_word.lower() in statement_uris:
|
| 147 |
key = relation_word.lower() + str(len(statement_uris))
|
| 148 |
else:
|
| 149 |
key = relation_word.lower()
|
| 150 |
statement_uris[key] = stmt_uri
|
| 151 |
-
add_triplet(g, stmt_uri, RDF.subject,
|
| 152 |
-
add_triplet(g, stmt_uri, RDF.object,
|
| 153 |
-
add_triplet(g, stmt_uri, RDF.predicate,
|
| 154 |
add_triplet(g, stmt_uri, RDF.value, Literal(cardinal))
|
| 155 |
|
| 156 |
if distance:
|
| 157 |
-
stmt_uri =
|
| 158 |
if relation_word.lower() in statement_uris:
|
| 159 |
key = relation_word.lower() + str(len(statement_uris))
|
| 160 |
else:
|
| 161 |
key = relation_word.lower()
|
| 162 |
statement_uris[key] = stmt_uri
|
| 163 |
-
add_triplet(g, stmt_uri, RDF.subject,
|
| 164 |
-
add_triplet(g, stmt_uri, RDF.object,
|
| 165 |
-
add_triplet(g, stmt_uri, RDF.predicate,
|
| 166 |
add_triplet(g, stmt_uri, RDF.value, Literal(distance))
|
| 167 |
|
| 168 |
|
|
|
|
| 105 |
|
| 106 |
return None
|
| 107 |
|
| 108 |
+
def link_to_subject_object(g, head_type, head_uri, relation_type, relation_word, prev_span, next_span, statement_uris, EKG, RDF):
|
| 109 |
|
| 110 |
relation_triplets = {}
|
| 111 |
with open('./assets/reference_triplet_relation.csv', mode='r', encoding='utf-8') as f:
|
|
|
|
| 126 |
|
| 127 |
# cas où le prédicat est une distance ou une orientation
|
| 128 |
if relation_type != "Distance-Orientation":
|
| 129 |
+
stmt_uri = EKG[f"Statement{len(statement_uris)}"]
|
| 130 |
|
| 131 |
if relation_word.lower() in statement_uris:
|
| 132 |
key = relation_word.lower() + str(len(statement_uris))
|
|
|
|
| 134 |
key = relation_word.lower()
|
| 135 |
|
| 136 |
statement_uris[key] = stmt_uri
|
| 137 |
+
add_triplet(g, stmt_uri, RDF.subject, EKG[subject_uri])
|
| 138 |
+
add_triplet(g, stmt_uri, RDF.object, EKG[next_span['uri']])
|
| 139 |
+
add_triplet(g, stmt_uri, RDF.predicate, EKG[relation_type.lower()])
|
| 140 |
else:
|
| 141 |
cardinal = identifier_cardinal(relation_word)
|
| 142 |
distance = identifier_distance(relation_word)
|
| 143 |
|
| 144 |
if cardinal:
|
| 145 |
+
stmt_uri = EKG[f"Statement{len(statement_uris)}"]
|
| 146 |
if relation_word.lower() in statement_uris:
|
| 147 |
key = relation_word.lower() + str(len(statement_uris))
|
| 148 |
else:
|
| 149 |
key = relation_word.lower()
|
| 150 |
statement_uris[key] = stmt_uri
|
| 151 |
+
add_triplet(g, stmt_uri, RDF.subject, EKG[subject_uri])
|
| 152 |
+
add_triplet(g, stmt_uri, RDF.object, EKG[next_span['uri']])
|
| 153 |
+
add_triplet(g, stmt_uri, RDF.predicate, EKG['orientation'])
|
| 154 |
add_triplet(g, stmt_uri, RDF.value, Literal(cardinal))
|
| 155 |
|
| 156 |
if distance:
|
| 157 |
+
stmt_uri = EKG[f"Statement{len(statement_uris)}"]
|
| 158 |
if relation_word.lower() in statement_uris:
|
| 159 |
key = relation_word.lower() + str(len(statement_uris))
|
| 160 |
else:
|
| 161 |
key = relation_word.lower()
|
| 162 |
statement_uris[key] = stmt_uri
|
| 163 |
+
add_triplet(g, stmt_uri, RDF.subject, EKG[subject_uri])
|
| 164 |
+
add_triplet(g, stmt_uri, RDF.object, EKG[next_span['uri']])
|
| 165 |
+
add_triplet(g, stmt_uri, RDF.predicate, EKG['distance'])
|
| 166 |
add_triplet(g, stmt_uri, RDF.value, Literal(distance))
|
| 167 |
|
| 168 |
|