Spaces:
Sleeping
Sleeping
RDF Validation Deployment commited on
Commit Β·
06231f2
1
Parent(s): 1487636
Fix HuggingFace Spaces configuration in README.md - 2025-10-04 15:16:48
Browse files
README.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
# π BIBFRAME Ontology Documentation MCP Server
|
| 2 |
|
| 3 |
A Model Context Protocol (MCP) server that provides BIBFRAME ontology documentation for LLMs like Claude. Built with Gradio, this server dynamically loads from the official BIBFRAME ontology at id.loc.gov.
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: BIBFRAME Ontology Documentation MCP Server
|
| 3 |
+
emoji: π
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: green
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: "5.0.0"
|
| 8 |
+
app_file: app.py
|
| 9 |
+
pinned: false
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
# π BIBFRAME Ontology Documentation MCP Server
|
| 13 |
|
| 14 |
A Model Context Protocol (MCP) server that provides BIBFRAME ontology documentation for LLMs like Claude. Built with Gradio, this server dynamically loads from the official BIBFRAME ontology at id.loc.gov.
|
app.py
CHANGED
|
@@ -33,12 +33,38 @@ class BIBFRAMEKnowledgeBase:
|
|
| 33 |
self.classes = {}
|
| 34 |
self._loaded = False
|
| 35 |
|
| 36 |
-
@lru_cache(maxsize=1)
|
| 37 |
def load_ontology(self):
|
| 38 |
"""Load the BIBFRAME ontology from the official source"""
|
|
|
|
|
|
|
|
|
|
| 39 |
try:
|
| 40 |
print("π Loading BIBFRAME ontology from id.loc.gov...")
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
|
| 43 |
# Extract properties
|
| 44 |
for prop in self.ontology_graph.subjects(RDF.type, RDF.Property):
|
|
@@ -69,6 +95,7 @@ class BIBFRAMEKnowledgeBase:
|
|
| 69 |
|
| 70 |
except Exception as e:
|
| 71 |
print(f"β οΈ Error loading ontology: {e}")
|
|
|
|
| 72 |
print("π¦ Using minimal fallback data")
|
| 73 |
self._load_minimal_fallback()
|
| 74 |
|
|
@@ -82,9 +109,34 @@ class BIBFRAMEKnowledgeBase:
|
|
| 82 |
"domain": ["http://id.loc.gov/ontologies/bibframe/AdminMetadata"],
|
| 83 |
"range": ["http://id.loc.gov/ontologies/bibframe/Agent"],
|
| 84 |
"subPropertyOf": []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
}
|
| 86 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
self._loaded = True
|
|
|
|
| 88 |
|
| 89 |
def _get_label(self, resource):
|
| 90 |
return str(self.ontology_graph.value(resource, RDFS.label) or "")
|
|
|
|
| 33 |
self.classes = {}
|
| 34 |
self._loaded = False
|
| 35 |
|
|
|
|
| 36 |
def load_ontology(self):
|
| 37 |
"""Load the BIBFRAME ontology from the official source"""
|
| 38 |
+
if self._loaded:
|
| 39 |
+
return
|
| 40 |
+
|
| 41 |
try:
|
| 42 |
print("π Loading BIBFRAME ontology from id.loc.gov...")
|
| 43 |
+
|
| 44 |
+
# Try with requests first for better error handling
|
| 45 |
+
headers = {
|
| 46 |
+
'User-Agent': 'BIBFRAME-MCP-Server/1.0 (https://github.com/your-repo)'
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
try:
|
| 50 |
+
response = requests.get(
|
| 51 |
+
"http://id.loc.gov/ontologies/bibframe.rdf",
|
| 52 |
+
headers=headers,
|
| 53 |
+
timeout=30
|
| 54 |
+
)
|
| 55 |
+
response.raise_for_status()
|
| 56 |
+
|
| 57 |
+
# Parse from string
|
| 58 |
+
self.ontology_graph.parse(data=response.text, format="xml")
|
| 59 |
+
print("π Successfully downloaded and parsed BIBFRAME ontology")
|
| 60 |
+
|
| 61 |
+
except requests.exceptions.RequestException as req_e:
|
| 62 |
+
print(f"β οΈ HTTP request failed: {req_e}")
|
| 63 |
+
# Fallback to direct parsing
|
| 64 |
+
self.ontology_graph.parse(
|
| 65 |
+
"http://id.loc.gov/ontologies/bibframe.rdf",
|
| 66 |
+
format="xml"
|
| 67 |
+
)
|
| 68 |
|
| 69 |
# Extract properties
|
| 70 |
for prop in self.ontology_graph.subjects(RDF.type, RDF.Property):
|
|
|
|
| 95 |
|
| 96 |
except Exception as e:
|
| 97 |
print(f"β οΈ Error loading ontology: {e}")
|
| 98 |
+
print(f"β οΈ Error type: {type(e).__name__}")
|
| 99 |
print("π¦ Using minimal fallback data")
|
| 100 |
self._load_minimal_fallback()
|
| 101 |
|
|
|
|
| 109 |
"domain": ["http://id.loc.gov/ontologies/bibframe/AdminMetadata"],
|
| 110 |
"range": ["http://id.loc.gov/ontologies/bibframe/Agent"],
|
| 111 |
"subPropertyOf": []
|
| 112 |
+
},
|
| 113 |
+
"bf:title": {
|
| 114 |
+
"uri": "http://id.loc.gov/ontologies/bibframe/title",
|
| 115 |
+
"label": "Title",
|
| 116 |
+
"definition": "Title information relating to a resource",
|
| 117 |
+
"domain": ["http://id.loc.gov/ontologies/bibframe/Work", "http://id.loc.gov/ontologies/bibframe/Instance"],
|
| 118 |
+
"range": ["http://id.loc.gov/ontologies/bibframe/Title"],
|
| 119 |
+
"subPropertyOf": []
|
| 120 |
}
|
| 121 |
}
|
| 122 |
+
|
| 123 |
+
self.classes = {
|
| 124 |
+
"bf:Work": {
|
| 125 |
+
"uri": "http://id.loc.gov/ontologies/bibframe/Work",
|
| 126 |
+
"label": "Work",
|
| 127 |
+
"definition": "Most abstract level of description for a creative concept",
|
| 128 |
+
"subClassOf": ["http://id.loc.gov/ontologies/bibframe/Resource"]
|
| 129 |
+
},
|
| 130 |
+
"bf:Instance": {
|
| 131 |
+
"uri": "http://id.loc.gov/ontologies/bibframe/Instance",
|
| 132 |
+
"label": "Instance",
|
| 133 |
+
"definition": "Individual exemplar of a Work",
|
| 134 |
+
"subClassOf": ["http://id.loc.gov/ontologies/bibframe/Resource"]
|
| 135 |
+
}
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
self._loaded = True
|
| 139 |
+
print("π¦ Loaded fallback data: 2 properties, 2 classes")
|
| 140 |
|
| 141 |
def _get_label(self, resource):
|
| 142 |
return str(self.ontology_graph.value(resource, RDFS.label) or "")
|