From b165a0b2adda375327379e1b4e0d0ae024e4ba52 Mon Sep 17 00:00:00 2001 From: Richard Newman Date: Wed, 15 Feb 2017 15:53:13 -0800 Subject: [PATCH] Implement Schema::attribute_for_ident. --- core/Cargo.toml | 2 ++ core/src/lib.rs | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/core/Cargo.toml b/core/Cargo.toml index 9494f61b..f400f57a 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -6,3 +6,5 @@ version = "0.0.1" num = "0.1.35" ordered-float = "0.4.0" +[dependencies.edn] +path = "../edn" diff --git a/core/src/lib.rs b/core/src/lib.rs index 7ec9162d..ba072337 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -8,10 +8,12 @@ // CONDITIONS OF ANY KIND, either express or implied. See the License for the // specific language governing permissions and limitations under the License. +extern crate edn; extern crate ordered_float; use std::collections::BTreeMap; use self::ordered_float::OrderedFloat; +use self::edn::NamespacedKeyword; /// Core types defining a Mentat knowledge base. @@ -224,6 +226,12 @@ impl Schema { self.schema_map.get(&x) } + pub fn attribute_for_ident(&self, ident: &NamespacedKeyword) -> Option<&Attribute> { + let s = ident.to_string(); // TODO: don't do this. #291. + self.get_entid(&s) + .and_then(|x| self.attribute_for_entid(x)) + } + /// Return true if the provided entid identifies an attribute in this schema. pub fn is_attribute(&self, x: Entid) -> bool { self.schema_map.contains_key(&x)