예제 #1
0
    def _load_stops_mapping(self):
        """Load the mapping from ALEX stops format (city + pronounceable name) into IDOS
        format (IDOS list + IDOS name including abbreviations and whatever rubbish).
        Also creates a reverse mapping of stop names, so that pronounceable names are
        returned.

        Updates the mapping from the server if needed

        @rtype: tuple
        @return: Mapping (city, stop) -> (idos_list, idos_stop), mapping (idos_stop) -> (stop)
        """
        # update the mapping file from the server
        online_update(
            to_project_path(
                os.path.join(os.path.dirname(__file__),
                             self.CONVERSION_FNAME)))
        # load the mapping
        mapping = {}
        reverse_mapping = {}
        with codecs.open(os.path.join(self.file_dir, self.CONVERSION_FNAME),
                         'r', 'UTF-8') as fh:
            for line in fh:
                line = line.strip()
                city, stop, idos_list, idos_stop = line.split("\t")
                mapping[(city, stop)] = (idos_list, idos_stop)
                idos_stop = self._normalize_idos_name(idos_stop)
                reverse_mapping[idos_stop] = stop
        return mapping, reverse_mapping
예제 #2
0
파일: directions.py 프로젝트: vikrantt/alex
    def _load_stops_mapping(self):
        """Load the mapping from ALEX stops format (city + pronounceable name) into IDOS
        format (IDOS list + IDOS name including abbreviations and whatever rubbish).
        Also creates a reverse mapping of stop names, so that pronounceable names are
        returned.

        Updates the mapping from the server if needed

        @rtype: tuple
        @return: Mapping (city, stop) -> (idos_list, idos_stop), mapping (idos_stop) -> (stop)
        """
        # update the mapping file from the server
        online_update(to_project_path(os.path.join(os.path.dirname(__file__), self.CONVERSION_FNAME)))
        # load the mapping
        mapping = {}
        reverse_mapping = {}
        with codecs.open(os.path.join(self.file_dir, self.CONVERSION_FNAME), 'r', 'UTF-8') as fh:
            for line in fh:
                line = line.strip()
                city, stop, idos_list, idos_stop = line.split("\t")
                mapping[(city, stop)] = (idos_list, idos_stop)
                idos_stop = self._normalize_idos_name(idos_stop)
                reverse_mapping[idos_stop] = stop
        return mapping, reverse_mapping
예제 #3
0
파일: ontology.py 프로젝트: m2rtin/alex
from __future__ import unicode_literals
from database import database
import codecs
import os
from alex.utils.config import online_update, to_project_path

# tab-separated file containing street + city + lon|lat coordinates + slot_specification
STREETS_TYPES_FNAME = 'streets.types.csv'
# tab-separated file containing stop + city + lon|lat coordinates
GENERAL_STOPS_LOCATIONS_FNAME = 'stops.locations.csv'
BOROUGH_STOPS_LOCATIONS_FNAME = 'stops.borough.locations.csv'
# tab-separated file containing city + state + lon|lat coordinates
CITIES_LOCATIONS_FNAME = 'cities.locations.csv'

# load new versions of the data files from the server
online_update(to_project_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), STREETS_TYPES_FNAME)))
online_update(to_project_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), GENERAL_STOPS_LOCATIONS_FNAME)))
online_update(to_project_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), BOROUGH_STOPS_LOCATIONS_FNAME)))
online_update(to_project_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), CITIES_LOCATIONS_FNAME)))

ontology = {
    'slots': {
        'silence': set([]),
        'ludait': set([]),
        'task': set(['find_connection', 'find_platform', 'weather']),
        'from': set([]),
        'to': set([]),
        'via': set([]),
        'in': set([]),
        'stop': set([]),
        'street': set([]),
예제 #4
0
# name of the file with one stop per line, assumed to reside in the same
# directory as this script
#
# The file is expected to have this format:
#   <value>; <phrase>; <phrase>; ...
# where <value> is the value for a slot and <phrase> is its possible surface
# form.
STREETS_FNAME = "streets.expanded.txt"
STOPS_FNAME = "stops.expanded.txt"
BOROUGHS_FNAME = "boroughs.expanded.txt"
CITIES_FNAME = "cities.expanded.txt"
STATES_FNAME = "states.expanded.txt"

# load new stops & cities list from the server if needed
online_update(to_project_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), STREETS_FNAME)))
online_update(to_project_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), STOPS_FNAME)))
online_update(to_project_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), BOROUGHS_FNAME)))
online_update(to_project_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), CITIES_FNAME)))
online_update(to_project_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), STATES_FNAME)))


def db_add(category_label, value, form):
    """A wrapper for adding a specified triple to the database."""
#    category_label = category_label.strip()
#    value = value.strip()
#    form = form.strip()

    if len(value) == 0 or len(form) == 0:
        return
예제 #5
0
파일: database.py 프로젝트: UFAL-DSG/alex
               "osmnáctý", "devatenáctý", "dvacátý", "jednadvacátý",
               "dvaadvacátý", "třiadvacátý"]

# name of the file with one stop per line, assumed to reside in the same
# directory as this script
#
# The file is expected to have this format:
#   <value>; <phrase>; <phrase>; ...
# where <value> is the value for a slot and <phrase> is its possible surface
# form.
STOPS_FNAME = "stops.expanded.txt"
CITIES_FNAME = "cities.expanded.txt"
TRAIN_NAMES_FNAME = "train_names.expanded.txt"

# load new stops & cities list from the server if needed
online_update(to_project_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), STOPS_FNAME)))
online_update(to_project_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), CITIES_FNAME)))
online_update(to_project_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), TRAIN_NAMES_FNAME)))


def db_add(category_label, value, form):
    """A wrapper for adding a specified triple to the database."""
#    category_label = category_label.strip()
#    value = value.strip()
#    form = form.strip()

    if len(value) == 0 or len(form) == 0:
        return

    if value in database[category_label] and isinstance(database[category_label][value], list):
        database[category_label][value] = set(database[category_label][value])
예제 #6
0
파일: database.py 프로젝트: tkraut/alex
    "devatenáctý", "dvacátý", "jednadvacátý", "dvaadvacátý", "třiadvacátý"
]

# name of the file with one stop per line, assumed to reside in the same
# directory as this script
#
# The file is expected to have this format:
#   <value>; <phrase>; <phrase>; ...
# where <value> is the value for a slot and <phrase> is its possible surface
# form.
STOPS_FNAME = "stops.expanded.txt"
CITIES_FNAME = "cities.expanded.txt"

# load new stops & cities list from the server if needed
online_update(
    to_project_path(
        os.path.join(os.path.dirname(os.path.abspath(__file__)), STOPS_FNAME)))
online_update(
    to_project_path(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     CITIES_FNAME)))


def db_add(category_label, value, form):
    """A wrapper for adding a specified triple to the database."""
    #    category_label = category_label.strip()
    #    value = value.strip()
    #    form = form.strip()

    if len(value) == 0 or len(form) == 0:
        return
예제 #7
0
import codecs
import os
from alex.utils.config import online_update, to_project_path

# tab-separated file containing street + city + lon|lat coordinates + slot_specification
STREETS_TYPES_FNAME = 'streets.types.csv'
# tab-separated file containing stop + city + lon|lat coordinates
GENERAL_STOPS_LOCATIONS_FNAME = 'stops.locations.csv'
BOROUGH_STOPS_LOCATIONS_FNAME = 'stops.borough.locations.csv'
# tab-separated file containing city + state + lon|lat coordinates
CITIES_LOCATIONS_FNAME = 'cities.locations.csv'

# load new versions of the data files from the server
online_update(
    to_project_path(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     STREETS_TYPES_FNAME)))
online_update(
    to_project_path(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     GENERAL_STOPS_LOCATIONS_FNAME)))
online_update(
    to_project_path(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     BOROUGH_STOPS_LOCATIONS_FNAME)))
online_update(
    to_project_path(
        os.path.join(os.path.dirname(os.path.abspath(__file__)),
                     CITIES_LOCATIONS_FNAME)))

ontology = {
예제 #8
0
# -*- coding: utf-8 -*-

from __future__ import unicode_literals
from database import database
import codecs
import os
from alex.utils.config import online_update, to_project_path

# tab-separated file containing city + stop in that city, one per line
CITIES_STOPS_FNAME = 'cities_stops.tsv'
# tab-separated file containing city + all locations of the city/cities with this name
# (as pipe-separated longitude, latitude, district, region)
CITIES_LOCATION_FNAME = 'cities_locations.tsv'

# load new versions of the data files from the server
online_update(to_project_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), CITIES_STOPS_FNAME)))
online_update(to_project_path(os.path.join(os.path.dirname(os.path.abspath(__file__)), CITIES_LOCATION_FNAME)))

ontology = {
    'slots': {
        'silence': set([]),
        'ludait': set([]),
        'task': set(['find_connection', 'find_platform', 'weather']),
        'from': set([]),
        'to': set([]),
        'via': set([]),
        'in': set([]),
        'stop': set([]),
        'from_stop': set(['Zličín', 'Anděl', ]),
        'to_stop': set(['Zličín', 'Anděl', ]),
        'via_stop': set(['Zličín', 'Anděl', ]),