コード例 #1
0
def euro_2016():
    input_color = colored(
        "Please choose from the following options:\n"
        "Stats 'S', Highlights 'H', Live Streams 'L', "
        "Exit 'E'\n",
        'red',
        attrs=['bold'])

    # prompt user for input
    choose_menu = input(input_color).lower()

    if (choose_menu == "s"):
        Stats.choose_menu()
        euro_2016()

    elif (choose_menu == "h"):
        Streams.footballHighlights()
        euro_2016()

    elif (choose_menu == "l"):
        Streams.sportLinks()
        euro_2016()

    elif (choose_menu == "e"):
        Stats.Logout()

    # user must have entered invalid option
    else:
        euro_2016()
コード例 #2
0
def euro_2016():
    input_color = colored("Please choose from the following options:\n"
                          "Stats 'S', Highlights 'H', Live Streams 'L', "
                          "Exit 'E'\n", 'red', attrs=['bold'])

    # prompt user for input
    choose_menu = input(input_color).lower()

    if (choose_menu == "s"):
        Stats.choose_menu()
        euro_2016()

    elif (choose_menu == "h"):
        Streams.footballHighlights()
        euro_2016()

    elif (choose_menu == "l"):
        Streams.sportLinks()
        euro_2016()

    elif (choose_menu == "e"):
        Stats.Logout()

    # user must have entered invalid option
    else:
        euro_2016()
コード例 #3
0
ファイル: index.py プロジェクト: ondrejsotolar/ner-sedlar
def process_form(form):
    """Read data from form, process it and return nice HTML page."""
    logging.basicConfig()

    input_data = form.getfirst('text', get_default_text()).decode('utf8')

    warning = ''
    if len(input_data) > 1000:
        warning = u'Příliš mnoho dat. Pracuji pouze s prvními 1000 znaky.'
        input_data = input_data[:1000]

    tagger = CategoryTagger.CategoryTagger()
    input_stream = tokenizer.tokenize_string(input_data)
    procs = detectors.create_all()
    input_streams = itertools.tee(input_stream, len(procs))
    procs = [p.run(x) for (p, x) in zip(procs, input_streams)]

    result = tagger.tag(Streams.merge(procs))

    if want_json():
        header_ok('application/json')
        print '{'
        if warning:
            print '"warning": "%s",' % warning.encode('utf8')
        print '"data": %s' % Streams.json_sink(result).encode('utf8')
        print '}'
    else:
        result = Streams.html_sink(result, cgi.escape)
        header_ok('text/html')
        warn_tpl = load_template('warning')
        warning = warn_tpl.substitute(text=warning) if warning else ''
        run_main_template(load_template('results').substitute(results=result),
                          warning=warning)
コード例 #4
0
def football():
    input_color = colored("Please choose from the following options:\nStats 'S', Highlights 'H', Live Streams 'L', Exit 'E'\n",'red',attrs=['bold'])
    choose_menu = raw_input(input_color)

    if choose_menu == 'H' or choose_menu == 'h':
        Streams.highlights()
        Restart_menu()

    if choose_menu == 'l' or choose_menu == 'L':
        Streams.footballLinks()
        Restart_menu()
コード例 #5
0
def sink(inp):
    """
    Print list of entities to stdout in format suitable for processing with
    scripts from CNEC.
    """

    for entity in Streams.collector_filter(inp):
        if '\n' in entity.word:
            continue
        pos = entity.position
        typ = entity.attrs['typ'] or ''
        if 'Cprice' in typ:
            space_idx = entity.word.find(' ')
            emit(pos + space_idx + 1, entity.word[space_idx + 1:])
        elif typ == 'CName':
            emit_person(entity)
        elif typ == 'CAddress':
            emit_address(entity)
        elif typ == 'Aevent Bdate':
            emit_date(entity)
        elif typ == 'Aevent Bperiod':
            y1, _, y2 = entity.word.split(' ')
            emit(pos, y1)
            emit(pos + 7, y2)
        elif 'Bpercent' in typ:
            pass
        elif 'Cmeasurement' in typ:
            emit_measure(entity)
        elif typ == 'CLawNo':
            emit_law(entity)
        elif typ == 'COrganisation':
            emit_org(entity)
        else:
            emit(pos, entity.word)
コード例 #6
0
ファイル: Commands.py プロジェクト: bburns/Abby
    def Do(self):
        
        # Build the export file and wrap it in a stream object
        # bug: forgot self in filename in similar case - wound up overwriting stuff.abby file by passing None!!!!!
        # bug: must write in binary mode or screws up endline!!
        stream = Streams.Factory(self.filename, 'wb', self.streamtype)
        
        # Build a list command to get the objects to export
        # export all properties!
        cmd = List(self.abby, self.adjectives, showprops='all') #, groupby, sortby)
        layout = cmd.Do() # don't tie into history
        
        # Pass the layout object to the stream object, which will pull 
        # the information from the layout and write it to the file in the
        # proper format.
        stream.WriteFromLayout(layout)

        #, i think the list command will set this via abby.get!
#        self.abby.it = layout.ob #, set current object(s)

        # wrap the status string in a simple String layout object
        nobjects = len(layout.ob)
        s = "%d objects exported to file '%s'." % (nobjects, self.filename)
#        self.abby.status = s #, standardize this
        return Layouts.String(s)
コード例 #7
0
def Euro2016():
    input_color = colored("Please choose from the following options:\nStats 'S', Highlights 'H', Live Streams 'L', Exit 'E'\n",'red',attrs=['bold'])
    Choose_menu = input(input_color)

    while (Choose_menu != "s" and Choose_menu != "S" and Choose_menu != "h" and Choose_menu != "H" and Choose_menu != "l"
           and Choose_menu != "L" and Choose_menu != "E" and Choose_menu != "e"):
        Choose_menu = input("Please choose from the following options:\nStats 'S', Highlights 'H', Live Streams 'L'\n")

    if (Choose_menu == "s" or Choose_menu == "S"):
        Stats.Choose_Menu()
        Restart_Menu()

    if (Choose_menu == "H" or Choose_menu == "h"):
        Streams.footballHighlights()
        Restart_Menu()

    if (Choose_menu == "l" or Choose_menu == "L"):
        Streams.sportLinks()
        Restart_Menu()

    if (Choose_menu == "E" or Choose_menu == "e"):
        Stats.Logout()
コード例 #8
0
ファイル: Commands.py プロジェクト: bburns/Abby
    def Do(self):

        import Abby  # for exception

        # Build the import file and wrap it in a stream object
        ## print 'streamtype:',self.streamtype
        # may throw exception if file not found
        stream = Streams.Factory(self.filename, 'r', self.streamtype) 
        layout = Layouts.Factory(self.abby, stream.layouttype)
        
        ## print 'stream:',stream
        ## print 'layout:',layout
        
        #stream.ReadToLayout()
        
        # the stream will return tokens one by one from the file, 
        # and layout will parse the tokens into commands.
        
        # get a composite command object
        ## cmd = layout.ParseFrom(stream)
        ## layoutresult = cmd.Do()
        
        # more efficient to do this way, so don't get a huge honkin composite cmd!
        ob = Objects.Objs()
        errors = []
        try:
            for cmd in layout.Parse(stream):
                try:
                    # cmd will usually be an Add command
                    layout = cmd.Do()
                    #, build up a list of all the objects added so can report to user
                    ob.append(layout.ob)
                except Abby.AbbyError, e:
                    #. add error to a file also?
                    errors.append(str(e))
        except Exception, e: #, Parser.ParserError, e:
            #errors.append(e)
            #errors.append(str(e))
            raise # pass it on
コード例 #9
0
    def __init__(self, abby):

        log.debug('ConsoleUI init')

        self.abby = abby

        # get our parser object
        self.parser = Parser.Parser(abby)

        self.prompt = '> '

        date = Data.Date()
        self.intro = "\nWelcome to NeoMem Console\nUsing Abby (version %s)\n" % (
            abby.version)
        self.intro += str(abby) + '\n'
        self.intro += str(date) + '\n'

        # get our stream object (in this case, the console/stdio)
        #, this could be a PlainConsole, AnsiConsole, or HtmlConsole
        self.console = Streams.Console()

        # open transcript file
        self.transcript = open('transcript.txt', 'a')  # a=append
コード例 #10
0
        'red',
        attrs=['bold'])

    # prompt user for input
    choose_menu = input(input_color).lower()

    if (choose_menu == "s"):
        Stats.choose_menu()
        euro_2016()

    elif (choose_menu == "h"):
        Streams.footballHighlights()
        euro_2016()

    elif (choose_menu == "l"):
        Streams.sportLinks()
        euro_2016()

    elif (choose_menu == "e"):
        Stats.Logout()

    # user must have entered invalid option
    else:
        euro_2016()


if __name__ == "__main__":
    # If this file is program entry point, execute:
    Streams.login()
    euro_2016()
コード例 #11
0
def main():
    """
    Parse argument and run the program.
    """
    parser = argparse.ArgumentParser(description='Named Entity Extractor')
    parser.add_argument('-v',
                        '--verbose',
                        help='print verbose output of what is happening',
                        action='store_true')
    parser.add_argument('-l',
                        '--list-detectors',
                        help='list available detectors',
                        action='store_true')
    parser.add_argument('detector',
                        metavar='DETECTOR',
                        type=str,
                        nargs='*',
                        help='which detectors to run')
    parser.add_argument('-f',
                        '--format',
                        metavar='FORMAT',
                        type=str,
                        default='markable',
                        help='select output format',
                        choices=FORMATS)
    parser.add_argument('--list-formats',
                        help='list available output formats',
                        action='store_true')
    parser.add_argument('-s',
                        '--skip-freebase',
                        help='skip category tagging via Freebase',
                        action='store_true')

    args = parser.parse_args()

    handle_listing(args)  # May exit the program

    if not args.detector:
        sys.stderr.write('No detector selected\n')
        list_detectors(sys.stderr)
        sys.exit(1)

    if args.detector == ['all']:
        procs = detectors.create_all()
    else:
        procs = [detectors.create_detector(det) for det in args.detector]

    tagger = CategoryTagger.CategoryTagger()

    logging.basicConfig()
    log_level = logging.WARNING
    if args.verbose:
        log_level = logging.DEBUG
        tagger.set_log_level(logging.DEBUG)
        for proc in procs:
            proc.set_log_level(logging.DEBUG)

    input_stream = tokenizer.tokenize(sys.stdin)
    input_streams = itertools.tee(input_stream, len(procs))
    procs = [p.run(x) for (p, x) in zip(procs, input_streams)]

    joined = Streams.merge(procs, level=log_level)
    if not args.skip_freebase:
        joined = tagger.tag(joined)

    FORMATS[args.format](joined)
コード例 #12
0
import detectors
import tokenizer
import Streams
import CategoryTagger
import CNEC

import argparse
import cgi
import sys
import logging
import itertools

# Values of this dict should be unary functions expecting input stream.
FORMATS = {
    'markable': Streams.markable_sink,
    'html': lambda x: encode_print(Streams.html_sink(x, cgi.escape)),
    'cnec': CNEC.sink,
    'json': lambda x: encode_print(Streams.json_sink(x)),
    'unitok': Streams.unitok_sink
}


def encode_print(data):
    """Encode data to UTF-8 and print it."""
    print data.encode('utf8')


def list_detectors(out):
    """List available detectors to supplied stream."""
    out.write('Available detectors:\n')
    for (nam, desc) in detectors.list_detectors():
コード例 #13
0
                          "Stats 'S', Highlights 'H', Live Streams 'L', "
                          "Exit 'E'\n", 'red', attrs=['bold'])

    # prompt user for input
    choose_menu = input(input_color).lower()

    if (choose_menu == "s"):
        Stats.choose_menu()
        euro_2016()

    elif (choose_menu == "h"):
        Streams.footballHighlights()
        euro_2016()

    elif (choose_menu == "l"):
        Streams.sportLinks()
        euro_2016()

    elif (choose_menu == "e"):
        Stats.Logout()

    # user must have entered invalid option
    else:
        euro_2016()


if __name__ == "__main__":
    # If this file is program entry point, execute:
    Streams.login()
    euro_2016()