| 1 | //! 拿真实公开本体探一遍投影结果。用法:cargo run -p utopia-ingest --example owl_probe -- <文件> |
| 2 | fn main() -> anyhow::Result<()> { |
| 3 | let path = std::env::args().nth(1).expect("需要文件路径"); |
| 4 | let bytes = std::fs::read(&path)?; |
| 5 | let fmt = utopia_ingest::ontology_rdf::RdfFormat::detect(&path, &bytes); |
| 6 | let p = utopia_ingest::ontology_rdf::project(&bytes, fmt)?; |
| 7 | println!( |
| 8 | "格式 {fmt:?} · 三元组 {} · 类 {} · 属性 {}", |
| 9 | p.triples, |
| 10 | p.classes.len(), |
| 11 | p.properties.len() |
| 12 | ); |
| 13 | println!("\n-- 类(前 6)--"); |
| 14 | for c in p.classes.iter().take(6) { |
| 15 | println!( |
| 16 | " {} | {} | 父 {} | 描述 {}", |
| 17 | c.key, |
| 18 | c.label, |
| 19 | c.parents.len(), |
| 20 | if c.description.is_empty() { |
| 21 | "(无)".into() |
| 22 | } else { |
| 23 | format!("{}…", c.description.chars().take(50).collect::<String>()) |
| 24 | } |
| 25 | ); |
| 26 | } |
| 27 | println!("\n-- 属性(前 6)--"); |
| 28 | for r in p.properties.iter().take(6) { |
| 29 | println!( |
| 30 | " {} | {} | {}{}{} | domain {} range {}", |
| 31 | r.key, |
| 32 | r.label, |
| 33 | if r.is_datatype { "字面值" } else { "对象" }, |
| 34 | if r.functional { " ·functional" } else { "" }, |
| 35 | if r.inverse_functional { |
| 36 | " ·inv_functional" |
| 37 | } else { |
| 38 | "" |
| 39 | }, |
| 40 | r.domains.len(), |
| 41 | r.ranges.len() |
| 42 | ); |
| 43 | } |
| 44 | println!("\n-- 暂未投影(前 8)--"); |
| 45 | let mut u: Vec<_> = p.unprojected.iter().collect(); |
| 46 | u.sort_by_key(|(_, n)| std::cmp::Reverse(**n)); |
| 47 | for (k, n) in u.into_iter().take(8) { |
| 48 | println!(" {n:4} × {k}"); |
| 49 | } |
| 50 | Ok(()) |
| 51 | } |