entity_linking¶
knowledge_graph.news.entity_linking
Recognize and link news entities with spaCy or ReLiK, using document or segment inputs.
to_document_offsets(entity, segment)
¶
Source code in src/knowledge_graph/news/entity_linking.py
30 31 32 33 34 35 36 | |
is_proper_name(surface)
¶
Whether a spaCy span looks like a proper name rather than a generic word, date, or number.
Source code in src/knowledge_graph/news/entity_linking.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | |
linker_qid(value)
¶
The linker reports numeric Wikidata IDs; return them as QIDs.
Source code in src/knowledge_graph/news/entity_linking.py
61 62 63 64 65 66 | |
linker_spans(doc)
¶
Linker spans that carry a Wikidata QID, deduplicated by span and QID.
Source code in src/knowledge_graph/news/entity_linking.py
69 70 71 72 73 74 75 76 77 78 79 | |
proper_names(doc)
¶
Proper-name spaCy spans, each with the QID of the best linker span overlapping 80% of the longer span.
Source code in src/knowledge_graph/news/entity_linking.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | |
SpacyLinker
¶
spaCy proper names linked to Wikidata.
Source code in src/knowledge_graph/news/entity_linking.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
nlp = spacy.load(SPACY)
instance-attribute
¶
predict(document, segments)
¶
Source code in src/knowledge_graph/news/entity_linking.py
118 119 120 121 122 123 124 | |
qid_of_candidate(candidate)
¶
QID of a retrieved candidate, from its ID or its metadata (index-dependent).
Source code in src/knowledge_graph/news/entity_linking.py
127 128 129 130 131 132 133 134 135 136 137 | |
candidate_qids_by_title(result)
¶
QIDs of retrieved candidates (e.g. of the 2M-popular index) by normalized title; the first candidate wins.
Source code in src/knowledge_graph/news/entity_linking.py
140 141 142 143 144 145 146 147 148 149 150 151 152 | |
ReLiK
¶
ReLiK mentions with Wikipedia titles and available candidate QIDs.
Source code in src/knowledge_graph/news/entity_linking.py
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
model = load_relik(index)
instance-attribute
¶
predict(document, segments)
¶
ReLiK spans of every segment at document offsets, with the candidate QID when the index provides one.
Source code in src/knowledge_graph/news/entity_linking.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 | |
main()
¶
Source code in src/knowledge_graph/news/entity_linking.py
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |