Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -235,27 +235,45 @@ def run_ontology_structure_analysis():
|
|
235 |
|
236 |
def run_entity_exploration():
|
237 |
st.title("Entity Exploration")
|
238 |
-
|
239 |
-
# Get all entities
|
240 |
entities = []
|
241 |
for class_name in ontology_manager.get_classes():
|
242 |
-
|
243 |
-
|
|
|
|
|
244 |
# Remove duplicates and sort
|
245 |
entities = sorted(set(entities))
|
246 |
|
247 |
-
# Debug
|
248 |
st.write("Loaded entities:", entities)
|
249 |
-
|
250 |
st.write("Ontology classes:", ontology_manager.get_classes())
|
251 |
-
|
252 |
-
# 額外 debug: 顯示所有節點類型與 class_type
|
253 |
for node, attr in ontology_manager.graph.nodes(data=True):
|
254 |
if attr.get("type") == "instance":
|
255 |
st.write("Found instance:", node, "of class:", attr.get("class_type"))
|
256 |
-
|
257 |
-
|
258 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
|
260 |
if selected_entity:
|
261 |
# Get entity information
|
|
|
235 |
|
236 |
def run_entity_exploration():
|
237 |
st.title("Entity Exploration")
|
238 |
+
|
239 |
+
# Get all entities from graph based on instance type
|
240 |
entities = []
|
241 |
for class_name in ontology_manager.get_classes():
|
242 |
+
class_entities = ontology_manager.get_instances_of_class(class_name)
|
243 |
+
if class_entities:
|
244 |
+
entities.extend(class_entities)
|
245 |
+
|
246 |
# Remove duplicates and sort
|
247 |
entities = sorted(set(entities))
|
248 |
|
249 |
+
# Debug: print full entity list and their types
|
250 |
st.write("Loaded entities:", entities)
|
|
|
251 |
st.write("Ontology classes:", ontology_manager.get_classes())
|
|
|
|
|
252 |
for node, attr in ontology_manager.graph.nodes(data=True):
|
253 |
if attr.get("type") == "instance":
|
254 |
st.write("Found instance:", node, "of class:", attr.get("class_type"))
|
255 |
+
|
256 |
+
if entities:
|
257 |
+
selected_entity = st.selectbox("Select Entity", entities)
|
258 |
+
|
259 |
+
if selected_entity:
|
260 |
+
entity_info = ontology_manager.get_entity_info(selected_entity)
|
261 |
+
display_entity_details(entity_info, ontology_manager)
|
262 |
+
|
263 |
+
if st.button("View this Entity in the Knowledge Graph"):
|
264 |
+
st.session_state.central_entity = selected_entity
|
265 |
+
st.rerun()
|
266 |
+
|
267 |
+
st.subheader("Entity Neighborhood")
|
268 |
+
max_distance = st.slider("Maximum Neighborhood Distance", 1, 3, 1)
|
269 |
+
neighborhood = knowledge_graph.get_entity_neighborhood(
|
270 |
+
selected_entity,
|
271 |
+
max_distance=max_distance,
|
272 |
+
include_classes=True
|
273 |
+
)
|
274 |
+
# Optional: visualize neighborhood or print debug info
|
275 |
+
else:
|
276 |
+
st.warning("No entities found in the ontology.")
|
277 |
|
278 |
if selected_entity:
|
279 |
# Get entity information
|