[crawler_platform 삭제]
This commit is contained in:
35
ontology_platform/crawler_platform/app/adapters/base.py
Normal file
35
ontology_platform/crawler_platform/app/adapters/base.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from typing import Any
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class DomainAdapter:
|
||||
"""Domain-specific semantics plugged into the generic ontology engine."""
|
||||
|
||||
domain: str
|
||||
relation_rules: dict[str, Any] = field(default_factory=dict)
|
||||
entity_type_aliases: dict[str, str] = field(default_factory=dict)
|
||||
entity_name_aliases: dict[str, dict[str, str]] = field(default_factory=dict)
|
||||
|
||||
def relation_rule(self, predicate: str) -> Any | None:
|
||||
return self.relation_rules.get(predicate)
|
||||
|
||||
def normalize_entity_type(self, raw_type: str) -> str | None:
|
||||
key = compact_key(raw_type)
|
||||
return self.entity_type_aliases.get(key)
|
||||
|
||||
def normalize_entity_name(self, raw_name: str, entity_type: str | None = None) -> str | None:
|
||||
if not entity_type:
|
||||
return None
|
||||
aliases = self.entity_name_aliases.get(entity_type, {})
|
||||
return aliases.get(canonical_key(raw_name))
|
||||
|
||||
|
||||
def compact_key(value: Any) -> str:
|
||||
return "".join(ch for ch in str(value or "").strip().lower() if ch.isalnum())
|
||||
|
||||
|
||||
def canonical_key(value: Any) -> str:
|
||||
return " ".join(str(value or "").strip().lower().split())
|
||||
Reference in New Issue
Block a user