Example #1
0
 def __init__(self):
     self.sctp_client = SctpClient()
     self.sctp_client.initialize("localhost", 55770)
     self.question = self.sctp_client.find_element_by_system_identifier(
         "question")
     self.question_initiated = self.sctp_client.find_element_by_system_identifier(
         "question_initiated")
Example #2
0
def new_sctp_client():
    sctp_client = SctpClient()
    sctp_client.initialize(tornado.options.options['sctp_host'],
                           tornado.options.options['sctp_port'])
    return sctp_client
Example #3
0
class AgentCaller:

    def __init__(self):
        self.sctp_client = SctpClient()
        self.sctp_client.initialize("localhost", 55770)
        self.question = self.sctp_client.find_element_by_system_identifier("question")
        self.question_initiated = self.sctp_client.find_element_by_system_identifier(
            "question_initiated")

    def __del__(self):
        del self.sctp_client

    def call(self, question_name_idtf, question_node_idtf):
        question_name = self.sctp_client.find_element_by_system_identifier(question_name_idtf)
        question_node = self.sctp_client.find_element_by_system_identifier(question_node_idtf)

        self.sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm,
                                    self.question,
                                    question_node)
        self.sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm,
                                    question_name,
                                    question_node)
        self.sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm,
                                    self.question_initiated,
                                    question_node)
Example #4
0
class StationScWriter:
    sctp_client = SctpClient()

    def __init__(self):
        self.set_sctp_settings()

    def get_or_create_sc_node(self, sc_type, sc_idtf):
        sc_idtf = str(sc_idtf)
        sc_node = self.sctp_client.find_element_by_system_identifier(sc_idtf)
        if not sc_node:
            sc_node = self.sctp_client.create_node(sc_type)
            self.sctp_client.set_system_identifier(sc_node, sc_idtf)
            if sc_idtf.isdigit():
                number = self.sctp_client.find_element_by_system_identifier(
                    'integer')
                self.sctp_client.create_arc(
                    ScElementType.sc_type_arc_pos_const_perm, number, sc_node)
        return sc_node

    def set_sctp_settings(self):
        self.sctp_client.initialize('127.0.0.1', 55770)

    def stations(self):
        trains_with_stations = {}
        sc_node = self.sctp_client.find_element_by_system_identifier(
            'concept_railway_train')
        nrel_station = self.sctp_client.find_element_by_system_identifier(
            'nrel_rw_train_route')

        trains = self.sctp_client.iterate_elements(
            SctpIteratorType.SCTP_ITERATOR_3F_A_A, sc_node,
            ScElementType.sc_type_arc_pos_const_perm,
            ScElementType.sc_type_node | ScElementType.sc_type_const)
        print len(trains)
        for train in trains:
            train_name = self.get_russian_name(train[2])
            trains_with_stations[train_name] = []
            station_sets = self.sctp_client.iterate_elements(
                SctpIteratorType.SCTP_ITERATOR_5F_A_A_A_F, train[2],
                ScElementType.sc_type_arc_common | ScElementType.sc_type_const,
                ScElementType.sc_type_node | ScElementType.sc_type_const,
                ScElementType.sc_type_arc_pos_const_perm, nrel_station)
            for station_set in station_sets:
                stations = self.sctp_client.iterate_elements(
                    SctpIteratorType.SCTP_ITERATOR_3F_A_A, station_set[2],
                    ScElementType.sc_type_arc_pos_const_perm,
                    ScElementType.sc_type_node | ScElementType.sc_type_const)
                for station in stations:
                    station_name = self.get_russian_name(station[2])
                    if station_name not in trains_with_stations[train_name]:
                        trains_with_stations[train_name].append(station_name)
        return trains_with_stations

    def find_path(self):
        trains = self.stations()
        first_station = "Минск-Северный".decode('utf-8')
        second_station = "Масюковщина".decode('utf-8')
        for train, stations in trains.items():
            if first_station in stations and second_station in stations:
                print train

    def get_russian_name(self, sc_node):
        nrel_main_idtf = self.sctp_client.find_element_by_system_identifier(
            'nrel_main_idtf')
        russian = self.sctp_client.find_element_by_system_identifier('lang_ru')
        identifier = self.sctp_client.iterate_elements(
            SctpIteratorType.SCTP_ITERATOR_5F_A_A_A_F, sc_node,
            ScElementType.sc_type_arc_common | ScElementType.sc_type_const,
            ScElementType.sc_type_link,
            ScElementType.sc_type_arc_pos_const_perm, nrel_main_idtf)
        if identifier is not None:
            for res in identifier:
                idtf_addr = res[2]

                # check if founded main identifier is for used language
                langs = self.sctp_client.iterate_elements(
                    SctpIteratorType.SCTP_ITERATOR_3F_A_F, russian,
                    ScElementType.sc_type_arc_pos_const_perm, idtf_addr)
                idtf_value = self.sctp_client.get_link_content(idtf_addr)
                idtf_value = idtf_value.decode('utf-8')
                return idtf_value
Example #5
0
File: logic.py Project: Gr1N/sc-web
def new_sctp_client():
    sctp_client = SctpClient()
    sctp_client.initialize(settings.SCTP_HOST, settings.SCTP_PORT)
    return sctp_client
class CalendarScWriter:
    sctp_client = SctpClient()

    def __init__(self):
        self.set_sctp_settings()

    def get_or_create_sc_node(self, sc_type, sc_idtf):
        sc_idtf = str(sc_idtf)
        sc_node = self.sctp_client.find_element_by_system_identifier(sc_idtf)
        if not sc_node:
            sc_node = self.sctp_client.create_node(sc_type)
            self.sctp_client.set_system_identifier(sc_node, sc_idtf)
            if sc_idtf.isdigit():
                number = self.sctp_client.find_element_by_system_identifier(
                    'integer')
                self.sctp_client.create_arc(
                    ScElementType.sc_type_arc_pos_const_perm, number, sc_node)
        return sc_node

    def set_sctp_settings(self):
        self.sctp_client.initialize('127.0.0.1', 55770)

    def calendar_parse(self, events):
        user = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_const, 'user')
        google_calendar = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_const,
            'Google_calendar')
        calendar = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_const,
            'user_calendar')
        self.sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm,
                                    google_calendar, calendar)
        decomposition = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_node_norole
            | ScElementType.sc_type_const, 'nrel_decomposition')
        calendar_events_node = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_const,
            'user_calendar_events')
        dec_arc = self.sctp_client.create_arc(
            ScElementType.sc_type_const | ScElementType.sc_type_edge_common,
            calendar_events_node, calendar)
        self.sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm,
                                    decomposition, dec_arc)

        for event in events:
            event_name = event['summary']
            start_datetime = arrow.get(event['start'].get(
                'dateTime', event['start'].get('date'))).datetime
            sc_start_date_construction = self.build_date_construction(
                start_datetime)
            end_datetime = arrow.get(event['end'].get(
                'dateTime', event['end'].get('date'))).datetime
            sc_end_date_construction = self.build_date_construction(
                end_datetime)
            event = self.build_event_construction(event_name,
                                                  sc_start_date_construction,
                                                  sc_end_date_construction)
            self.sctp_client.create_arc(
                ScElementType.sc_type_arc_pos_const_perm, calendar_events_node,
                event)

    def create_link(self):
        node = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_node_class
            | ScElementType.sc_type_const, 'Elementary')
        lnk = self.sctp_client.create_link()
        res = self.sctp_client.set_link_content(lnk, 'True text off link')
        print res
        self.sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm,
                                    node, lnk)

    def build_event_construction(self, event_name, start_date, end_date):
        event = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_const,
            event_name)
        event_start_date_relation = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_node_norole
            | ScElementType.sc_type_const, 'nrel_start_event_date')
        event_end_date_relation = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_node_norole
            | ScElementType.sc_type_const, 'nrel_end_event_date')
        start_relation_arc = self.sctp_client.create_arc(
            ScElementType.sc_type_const | ScElementType.sc_type_edge_common,
            event, start_date)
        end_relation_arc = self.sctp_client.create_arc(
            ScElementType.sc_type_const | ScElementType.sc_type_edge_common,
            event, end_date)
        self.sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm,
                                    event_start_date_relation,
                                    start_relation_arc)
        self.sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm,
                                    event_end_date_relation, end_relation_arc)
        return event

    def build_date_construction(self, date):
        """
        Get node of date
        :param date: datetime object
        :return: day node
        """
        date_class = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_node_class
            | ScElementType.sc_type_const, 'date')
        geregorian_calendar = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_node_norole
            | ScElementType.sc_type_const, 'nrel_geregorian_calendar')
        node = self.sctp_client.create_node(ScElementType.sc_type_node
                                            | ScElementType.sc_type_const)
        date_class_arc = self.sctp_client.create_arc(
            ScElementType.sc_type_const | ScElementType.sc_type_edge_common,
            date_class, node)
        self.sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm,
                                    geregorian_calendar, date_class_arc)
        day = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_const, date.day)
        month = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_const,
            date.month)
        year = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_const,
            date.year)
        month_norole = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_node_role
            | ScElementType.sc_type_const, "rrel_the_month_of_the_year")
        year_norole = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_node_role
            | ScElementType.sc_type_const, "rrel_number_of_the_year")
        day_norole = self.get_or_create_sc_node(
            ScElementType.sc_type_node | ScElementType.sc_type_node_role
            | ScElementType.sc_type_const,
            "rrel_number_of_the_day_in_the_month")
        month_arc = self.sctp_client.create_arc(
            ScElementType.sc_type_arc_pos_const_perm, node, month)
        self.sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm,
                                    month_norole, month_arc)
        day_arc = self.sctp_client.create_arc(
            ScElementType.sc_type_arc_pos_const_perm, node, day)
        self.sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm,
                                    day_norole, day_arc)
        year_arc = self.sctp_client.create_arc(
            ScElementType.sc_type_arc_pos_const_perm, node, year)
        self.sctp_client.create_arc(ScElementType.sc_type_arc_pos_const_perm,
                                    year_norole, year_arc)

        return node
Example #7
0
def new_sctp_client():
    sctp_client = SctpClient()
    sctp_client.initialize(tornado.options.options['sctp_host'], tornado.options.options['sctp_port'])
    return sctp_client