Follow QueSucede on Twitter
    hacker emblem

    CrystalMind topic map engine

    IconDetails...




    CrystalMind is the name I gave to my topic map engine for no other reason than that the name stuck with me after reading the book The Last Legends of Earth and I thought it appropriate for a standard that's main objective is to achieve greater understanding.

    See the JCrystalMind topic map project hosted at GitHub for an implementation of the CrystalMind topic map engine/store in Java.

    The CrystalMind topic map engine has been successfully ported to Ruby, ActionScript 3 (Adobe AIR), Java (see link above, with branches for both MySQL and SQLite), PHP (for this site) and Android (Java). The original CrystalMind topic map engine was developed in Python.

    Topic map

    Click here for a more detailed overview of topic maps.

    Inheritance diagram

    A couple of notes with regards to the inheritance diagram above:

    • the Node class is the super class of all other classes within the topic map engine. The Node class basically provides its sub-classes with both an identifier and an instance-of property (see source below). Specifically, the identifier field is important because it makes all objects 'addressable' within the topic map.
    • the Association class inherits from the Topic class, meaning that associations themselves are topics! An example of when this could be of use will be provided below.

    Topic map

    A detailed explanation of associations and how they have been implemented in the CrystalMind topic map engine. Pending...

    node.py

    import uuid
    import unittest
    
    from utils import Utils
    
    #===============================================================================
    
    class Node:
    
      def __init__(self, identifier=None, instance_of='node'):
        self.__identifier = (str(uuid.uuid1()) if identifier is None 
          else Utils.sanitize_id(str(identifier)))
        self.__instance_of = Utils.sanitize_id(instance_of)
        self.__meta_data = []
    
      @property
      def identifier(self):
        return self.__identifier
    
      @property
      def instance_of(self):
        return self.__instance_of
    
      @instance_of.setter
      def instance_of(self, value):
        self.__instance_of = Utils.sanitize_id(instance_of)
    
      @property
      def meta_data(self):
        return self.__meta_data
    
      def add_meta_datum(self, meta_datum):
        for meta_datum in meta_data:
          self.__meta_data.append(meta_datum)
    
      def add_meta_data(self, meta_data):
        for meta_datum in meta_data:
          self.__meta_data.append(meta_datum)
    

    topic.py

    import unittest
    
    from node import Node
    from occurrence import Occurrence
    
    #===============================================================================
    
    class Topic(Node):
    
      def __init__(self,
          identifier=None,
          instance_of='topic',
          base_name='undefined'):
        super().__init__(identifier, instance_of)
    
        self.__base_names = [base_name]
        self.__occurrences = []
    
      @property
      def base_names(self):
        return self.__base_names
    
      @property
      def first_name(self):
        return self.__base_names[0]
    
      @property
      def occurrences(self):
        return self.__occurrences
    
      def add_basename(self, base_name):
        self.__base_names.append(base_name)
    
      def remove_basename(self, base_name):
        self.__base_names = list(item for item in self.__base_names if item != base_name)
    
      def clear_basenames(self):
        self.__base_names[:] = []
    
      def create_occurrence(self,
          identifer=None,
          instance_of='occurrence',
          scope='*',
          resource_ref='',
          resource_data=None):
        occurrence = Occurrence(
          self.identifier,
          identifier,
          instance_of,
          scope,
          resource_ref,
          resource_data)
        self.__occurrences.append(occurrence)
        return occurrence
    
      def add_occurrence(self, occurrence):
        occurrence.topic_identifier = self.__identifier
        self.__occurrences.append(occurrence)
    
      def add_occurrences(self, occurrences):
        for occurrence in occurrences:
          self.__occurrences.append(occurrence)
    

    occurrence.py

    import unittest
    
    from node import Node
    
    from utils import Utils
    
    #===============================================================================
    
    class Occurrence(Node):
    
      def __init__(self,
          topic_identifier='',
          identifier=None,
          instance_of='occurrence',
          scope='*',
          resource_ref='',
          resource_data=None):
    
        super().__init__(identifier, instance_of)
    
        self.__scope = Utils.sanitize_id(scope)
    
        self.topic_identifier = Utils.sanitize_id(topic_identifier)
        self.resource_ref = resource_ref
        self.resource_data = resource_data
    
      @property
      def scope(self):
        return self.__scope
    
      @scope.setter
      def scope(self, value):
        self.__scope = Utils.sanitize_id(value)
    

    member.py

    import uuid
    import unittest
    
    from utils import Utils
    
    #===============================================================================
    
    class Member:
    
      def __init__(self, role_spec, topic_ref=None, identifier=None):
        self.__identifier = (str(uuid.uuid1()) if identifier is None 
          else Utils.sanitize_id(str(identifier)))
        self.role_spec = Utils.sanitize_id(role_spec)
        self.topic_refs = [] if topic_ref is None else [Utils.sanitize_id(topic_ref)]
    
      @property
      def identifier(self):
        return self.__identifier
    
      def add_topicref(self, topic_ref):
        self.topic_refs.append(Utils.sanitize_id(topic_ref))
    
      def remove_topicref(self, topic_ref):
        self.topic_refs.remove(topic_ref)
    
      def clear_topicrefs(self):
        self.topic_refs[:] = []
    

    association.py

    import unittest
    
    from topic import Topic
    from member import Member
    
    from utils import Utils
    
    #===============================================================================
    
    class Association(Topic):
    
      def __init__(self,
          src_role_spec='',
          src_topic_ref='',
          dest_role_spec='',
          dest_topic_ref='',
          identifier=None,
          instance_of='association',
          scope='*',
          base_name='undefined'):
    
        super().__init__(identifier, instance_of, base_name)
    
        self.__members = []
        self.__scope = Utils.sanitize_id(scope)
    
        if (src_role_spec != '' and src_topic_ref != '' 
            and dest_role_spec != '' and dest_topic_ref != ''):
          src_member = Member(src_role_spec, src_topic_ref)
          dest_member = Member(dest_role_spec, dest_topic_ref)
          self.__members.append(src_member)
          self.__members.append(dest_member)
    
      @property
      def members(self):
        return self.__members
    
      @property
      def scope(self):
        return self.__scope
    
      @scope.setter
      def scope(self, value):
        self.__scope = Utils.sanitize_id(value)
    
      def create_member(self, role_spec, topic_ref):
        member = Member(role_spec, topic_ref)
        self.__members.append(member)
    
      def create_members(self, src_role_spec, src_topic_ref, dest_role_spec, dest_topic_ref):
        src_member = Member(src_role_spec, src_topic_ref)
        dest_member = Member(dest_role_spec, dest_topic_ref)
        self.__members.append(src_member)
        self.__members.append(dest_member)
    
      def add_member(self, member):
        self.__members.append(member)
    
      def get_member(self, identifier):
        pass
    
      def remove_member(self, identifier):
        self.__base_names = 
          list(item for item in self.__members if item.identifier != identifier)
    
      def clear_members(self):
        self.__members[:] = []
    

    Click here to be able to create pages, upload images and file attachments, and link to other users and their pages.


    blog comments powered by Disqus