ontocast.tool.aggregate¶
Graph aggregation for OntoCast.
This module re-exports the embedding-based aggregator as the main aggregation implementation. Use EmbeddingBasedAggregator for aggregating and disambiguating RDF graphs from multiple chunks.
EmbeddingBasedAggregator
¶
Main aggregator using embedding-based entity disambiguation.
This aggregator uses a clean pipeline: 1. Entity normalization (with semantic context) 2. Parallel embedding 3. Similarity-based clustering 4. Representative selection (prefer ontology, then simplicity) 5. URI promotion (chunk -> document namespace) 6. Graph rewriting
Attributes:
| Name | Type | Description |
|---|---|---|
normalizer |
Entity normalizer for creating representations |
|
clusterer |
Entity clusterer for grouping similar entities |
|
selector |
Representative selector for choosing best entity per group |
|
promoter |
Optional[URIPromoter]
|
URI promoter for chunk -> document namespace conversion |
rewriter |
Graph rewriter for applying entity mappings |
Source code in ontocast/tool/agg/aggregate.py
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 | |
__init__(ontology_namespaces=None, embedding_model='all-MiniLM-L6-v2', similarity_threshold=0.85, add_sameas_links=True)
¶
Initialize the embedding-based aggregator.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ontology_namespaces
|
Optional[set[str]]
|
Set of namespace URIs for ontology entities |
None
|
embedding_model
|
str
|
Name of sentence transformer model |
'all-MiniLM-L6-v2'
|
similarity_threshold
|
float
|
Cosine similarity threshold for clustering (0-1) |
0.85
|
add_sameas_links
|
bool
|
Whether to add owl:sameAs for merged entities |
True
|
Source code in ontocast/tool/agg/aggregate.py
aggregate_graphs(chunks, doc_namespace)
¶
Aggregate multiple chunk graphs with embedding-based disambiguation.
This is the main entry point that orchestrates the entire pipeline: 1. Collect entities from all chunks 2. Create normalized representations r(e) with semantic context 3. Embed all representations in parallel: r(e) -> v(e) 4. Cluster by similarity: v(e) -> g(e) 5. Select best representative per group: g(e) -> e_rep 6. Promote to document namespace: e_rep -> e' 7. Compose final mapping: e -> e' 8. Rewrite and merge all graphs
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunks
|
list[Chunk]
|
List of chunks to aggregate |
required |
doc_namespace
|
str
|
Document namespace for the aggregated graph |
required |
Returns:
| Type | Description |
|---|---|
RDFGraph
|
Aggregated RDF graph with disambiguated entities |
Source code in ontocast/tool/agg/aggregate.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 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 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |
aggregate_graphs_with_metadata(chunks, doc_namespace)
¶
Aggregate graphs and return additional metadata about the process.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunks
|
list[Chunk]
|
List of chunks to aggregate |
required |
doc_namespace
|
str
|
Document namespace |
required |
Returns:
| Type | Description |
|---|---|
RDFGraph
|
Tuple of (aggregated_graph, metadata_dict) |
dict
|
metadata_dict contains: - entity_mapping: Final e -> e' mapping - clusters: List of entity clusters - representations: Entity representations - embeddings: Entity embeddings |
Source code in ontocast/tool/agg/aggregate.py
aggregate_chunk_graphs(chunks, doc_namespace, ontology_namespaces=None, similarity_threshold=0.85)
¶
Convenience function to aggregate chunk graphs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunks
|
list[Chunk]
|
List of chunks to aggregate |
required |
doc_namespace
|
str
|
Document namespace |
required |
ontology_namespaces
|
Optional[set[str]]
|
Optional set of ontology namespaces |
None
|
similarity_threshold
|
float
|
Cosine similarity threshold for clustering |
0.85
|
Returns:
| Type | Description |
|---|---|
RDFGraph
|
Aggregated RDF graph |