Implement Schema::attribute_for_ident.

This commit is contained in:
Richard Newman 2017-02-15 15:53:13 -08:00
parent 16e9740d8a
commit b165a0b2ad
2 changed files with 10 additions and 0 deletions

View file

@ -6,3 +6,5 @@ version = "0.0.1"
num = "0.1.35"
ordered-float = "0.4.0"
[dependencies.edn]
path = "../edn"

View file

@ -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)