Exemplo n.º 1
0
 def smart_get(self, libfile, sources, depdirs, include_paths,
                  define_symbols, undefine_symbols, extra_opts,
                  working_dir, export_dirs, type_mappers=()):
     key = `[libfile, sources, depdirs, include_paths, define_symbols, undefine_symbols, extra_opts, working_dir, export_dirs]`
     cmd = ['g++', '-Wno-attributes', '-Wno-deprecated', '-shared'] + sources + ['-o', libfile, '-fPIC']
     cmd += ['-I'+inc for inc in include_paths]
     cmd += ['-D'+sym for sym in define_symbols]
     cmd += ['-U'+sym for sym in undefine_symbols]
     cmd += extra_opts
     command, deps, outputs = self.builder.run(cmd)
     rebuilt = (deps is not None) or (outputs is not None)
     retyped = False
     xml = self.getxml(libfile, force_rebuild=rebuilt)
     if xml is None:
         xml = parse(sources, working_directory=working_dir,
             include_paths = include_paths, define_symbols = define_symbols,
             undefine_symbols = undefine_symbols)
         self.savexml(libfile, xml)
         retyped = True
     return self.loadlib(key, libfile, rebuilt or retyped, xml, export_dirs, type_mappers = type_mappers)
Exemplo n.º 2
0
def upload_file():
    # check if the post request has the file part
    if 'file' not in request.files:
        return redirect(request.url)
    file = request.files['file']
    # if user does not select file, browser also
    # submit an empty part without filename
    if file.filename == '':
        return redirect(request.url)
    if file and allowed_file(file.filename):
        filename = secure_filename(file.filename)
        filepath = os.path.join(upload_folder, filename)
        file.save(filepath)
        res = parsexml.parse(open(filepath))
        print "Got %d points" % (len(res), )

        parsexml.insertpath(res, connection, cursor)

        return redirect("/")

    return 'failed'
Exemplo n.º 3
0
 def smart_get(self,
               libfile,
               sources,
               depdirs,
               include_paths,
               define_symbols,
               undefine_symbols,
               extra_opts,
               working_dir,
               export_dirs,
               type_mappers=()):
     key = ` [
         libfile, sources, depdirs, include_paths, define_symbols,
         undefine_symbols, extra_opts, working_dir, export_dirs
     ] `
     cmd = ['g++', '-Wno-attributes', '-Wno-deprecated', '-shared'
            ] + sources + ['-o', libfile, '-fPIC']
     cmd += ['-I' + inc for inc in include_paths]
     cmd += ['-D' + sym for sym in define_symbols]
     cmd += ['-U' + sym for sym in undefine_symbols]
     cmd += extra_opts
     command, deps, outputs = self.builder.run(cmd)
     rebuilt = (deps is not None) or (outputs is not None)
     retyped = False
     xml = self.getxml(libfile, force_rebuild=rebuilt)
     if xml is None:
         xml = parse(sources,
                     working_directory=working_dir,
                     include_paths=include_paths,
                     define_symbols=define_symbols,
                     undefine_symbols=undefine_symbols)
         self.savexml(libfile, xml)
         retyped = True
     return self.loadlib(key,
                         libfile,
                         rebuilt or retyped,
                         xml,
                         export_dirs,
                         type_mappers=type_mappers)
Exemplo n.º 4
0
    def add_item(self, item):
        pass


class Trees(ElementHandler):

    handlers = dict(Tree=Tree)


class Sentence(ElementHandler):

    handlers = dict(Trees=Trees)

    def start(self, name, attr):
        pass  # print attr["ID"]


class Sentences(ElementHandler):

    handlers = dict(Sentence=Sentence)


if len(sys.argv) > 1:
    with open(sys.argv[1]) as f:
        parse(f, {"Sentences": Sentences})
else:
    for filename in glob.glob("syntax-trees/*.xml"):
        with open(filename) as f:
            parse(f, {"Sentences": Sentences})
Exemplo n.º 5
0

def print_transitions(trans_features):
    for (label_from, label_to), weight in trans_features:
        print("%-6s -> %-7s %0.6f" % (label_from, label_to, weight))


def print_state_features(state_features):
    for (attr, label), weight in state_features:
        print("%0.6f %-6s %s" % (weight, label, attr))    


if __name__ == "__main__":
	# Import dataset
	# Data is list of pairs of words and tags [(word, tag)]
	sents, labels = parsexml.parse("20000410_nyt-NEW.xml")

	# Test data
	test_sents = []
	test_labels = []
	for filename in os.listdir("./featsdata/"):
		if filename.endswith(".xml"):
			print(filename)
			try:
				s, l = parsexml.parse("./featsdata/" + filename)
				test_sents += s
				test_labels += l
				print("done!")
			except Exception as e:
				print(e)
Exemplo n.º 6
0
import parsexml

xml = '<Foo foo="foo" foo1="foo 1">Foo</Foo>\n<Bar bar=bar>Bar</Bar>\n<Baz baz>Baz</Baz>'

parsed = parsexml.parse(xml)
print(parsed)
Exemplo n.º 7
0
    def add_item(self, item):
        pass


class Trees(ElementHandler):

    handlers = dict(Tree=Tree)


class Sentence(ElementHandler):

    handlers = dict(Trees=Trees)

    def start(self, name, attr):
        pass  # print attr["ID"]


class Sentences(ElementHandler):

    handlers = dict(Sentence=Sentence)


if len(sys.argv) > 1:
    with open(sys.argv[1]) as f:
        parse(f, {"Sentences": Sentences})
else:
    for filename in glob.glob("syntax-trees/*.xml"):
        with open(filename) as f:
            parse(f, {"Sentences": Sentences})
Exemplo n.º 8
0
    InStream = sys.stdin
else:
    InStream = args.inputfile

if args.isvalid is not None and args.g:
    print("Error wrong arguments", file=sys.stderr)
    sys.exit(1)

try:
    parser = ET.XMLParser(encoding="utf-8")
    tree = ET.parse(InStream)  # , parser=parser)
except:
    print("Error Parsing stream", file=sys.stderr)
    sys.exit(2)

tables = parsexml.parse(tree, args.a)

# parse etc argument, if not -b set
if not args.b:
    parsexml.process_etc(tables, args.etc)
elif args.etc is not None:
    print("Error Parsing arguments", file=sys.stderr)
    sys.exit(1)

#pprint.pprint(tables)

if args.outputfile is None:
    try:
        OutStream = sys.stdout
    except:
        print("Error Opening Output stream", file=sys.stderr)