def main(): quick = False nofail = False try: opts, args = getopt.getopt(sys.argv[1:], "E:srhdqVi", ["help"]) except getopt.GetoptError as err: print(str(err), file=sys.stderr) usage() sys.exit(2) for o, a in opts: if o == "-h" or o == "--help": usage() sys.exit(0) elif o == "-E": settings.extension = a elif o == "-r": settings.recurse = True elif o == "-d": settings.deep = True elif o == "-q": quick = True elif o == "-i": nofail = True elif o == "-V": print("FoLiA " + folia.FOLIAVERSION + ", library version " + folia.LIBVERSION, file=sys.stderr) sys.exit(0) else: raise Exception("No such option: " + o) schema = lxml.etree.RelaxNG(folia.relaxng()) if len(args) >= 1: success = True for x in sys.argv[1:]: if x[0] != "-": if os.path.isdir(x): r = processdir(x, schema, quick, settings.deep) elif os.path.isfile(x): r = validate(x, schema, quick, settings.deep) else: print("ERROR: File or directory not found: " + x, file=sys.stderr) sys.exit(3) if not r: success = False if not success and not nofail: sys.exit(1) else: print("ERROR: No files specified", file=sys.stderr) sys.exit(2)
def main(): quick = False try: opts, args = getopt.getopt(sys.argv[1:], "E:srhqV", ["help"]) except getopt.GetoptError as err: print(str(err), file=sys.stderr) usage() sys.exit(2) for o, a in opts: if o == '-h' or o == '--help': usage() sys.exit(0) elif o == '-E': settings.extension = a elif o == '-r': settings.recurse = True elif o == '-q': quick = True elif o == '-V': print("FoLiA " + folia.FOLIAVERSION + ", library version " + folia.LIBVERSION,file=sys.stderr) sys.exit(0) else: raise Exception("No such option: " + o) schema = lxml.etree.RelaxNG(folia.relaxng()) if len(args) >= 1: for x in sys.argv[1:]: if x[0] != '-': if os.path.isdir(x): processdir(x,schema,quick) elif os.path.isfile(x): validate(x, schema,quick) else: print("ERROR: File or directory not found: " + x,file=sys.stderr) sys.exit(3) else: print("ERROR: No files specified",file=sys.stderr) sys.exit(2)
for o, a in opts: if o == '-h' or o == '--help': usage() sys.exit(0) elif o == '-E': settings.extension = a elif o == '-r': settings.recurse = True else: raise Exception("No such option: " + o) schema = lxml.etree.RelaxNG(folia.relaxng()) if len(sys.argv) >= 2: for x in sys.argv[1:]: if os.path.isdir(x): processdir(x,schema) elif os.path.isfile(x): validate(x, schema) else: print >>sys.stderr, "ERROR: File or directory not found: " + x sys.exit(3) else: print >>sys.stderr,"ERROR: No files specified" sys.exit(2) if __name__ == "__main__":
if __name__ == '__main__': try: sonardir = sys.argv[1] foliadir = sys.argv[2] xsltfile = sys.argv[3] threads = int(sys.argv[4]) except: print >> sys.stderr, "Syntax: sonarconversion.py sonardir foliadir dcoi2folia.xsl threads" sys.exit(2) #Let XSLT do the basic conversion to HTML xslt = lxml.etree.parse(xsltfile) dcoitofoliatransformer = lxml.etree.XSLT(xslt) schema = lxml.etree.RelaxNG(folia.relaxng()) if foliadir[-1] != '/': foliadir += '/' try: os.mkdir(foliadir[:-1]) except: pass maxtasksperchild = 10 preindex = True processor = folia.CorpusProcessor(sonardir, process, threads, 'pos', "", lambda x: True, maxtasksperchild, preindex) for i, _ in enumerate(processor): progress = round((i + 1) / float(len(processor.index)) * 100, 1) print "#" + str(i) + " - " + str(progress) + '%'
#!/usr/bin/env python #-*- coding:utf-8 -*- import sys try: from pynlpl.formats import folia except ImportError: print >>sys.stderr,"PyNLPL is required to run this script, obtain it from https://github.com/proycon/pynlpl and either install it or make sure the pynlpl/ dir is symlinked from the directory this script is in." sys.exit(3) import codecs print "Generating Relax NG schema" folia.relaxng('folia-min.rng') #!/usr/bin/python data = codecs.open("folia-min.rng",'r','utf-8').readlines() data.insert(1,u"""<!-- RelaxNG schema for FoLiA XML v%s by Maarten van Gompel Induction of Linguistic Knowledge Research group Tilburg University http://ilk.uvt.nl/folia http://github.com/proycon/folia Schema version %s (auto-generated by pynlpl.formats.folia) Validation examples: $ xmllint ‒‒relaxng folia.rng foliadocument.xml $ jing folia.rng foliadocument.xml
#-*- coding:utf-8 -*- from __future__ import print_function, unicode_literals, division, absolute_import import sys try: from pynlpl.formats import folia except ImportError: print( "PyNLPL is required to run this script, obtain it from https://github.com/proycon/pynlpl and either install it or make sure the pynlpl/ dir is symlinked from the directory this script is in.", file=sys.stderr) sys.exit(3) import io print("Generating Relax NG schema") folia.relaxng('folia-min.rng') #!/usr/bin/python data = io.open("folia-min.rng", 'r', encoding='utf-8').readlines() data.insert( 1, """<!-- RelaxNG schema for FoLiA XML v%s by Maarten van Gompel Induction of Linguistic Knowledge Research group Tilburg University http://ilk.uvt.nl/folia http://github.com/proycon/folia Schema version %s (auto-generated by pynlpl.formats.folia)
def main(): quick = False nofail = False try: opts, args = getopt.getopt(sys.argv[1:], "E:D:WsrhdqVit", ["help"]) except getopt.GetoptError as err: print(str(err), file=sys.stderr) usage() sys.exit(2) for o, a in opts: if o == '-h' or o == '--help': usage() sys.exit(0) elif o == '-D': settings.debug = int(a) print("DEBUG level set to " + str(settings.debug), file=sys.stderr) elif o == '-E': settings.extension = a elif o == '-r': settings.recurse = True elif o == '-t': settings.stricttextvalidation = True elif o == '-d': settings.deep = True elif o == '-q': quick = True elif o == '-i': nofail = True elif o == '-W': settings.warn = False elif o == '-V': print("FoLiA " + folia.FOLIAVERSION + ", library version " + folia.LIBVERSION, file=sys.stderr) sys.exit(0) else: raise Exception("No such option: " + o) schema = lxml.etree.RelaxNG(folia.relaxng()) if len(args) >= 1: success = True skipnext = False for x in sys.argv[1:]: if x in ('-E', '-D'): skipnext = True continue elif x[0] != '-' and not skipnext: if os.path.isdir(x): r = processdir(x, schema, quick, settings.deep, settings.stricttextvalidation, settings.warn, settings.debug) elif os.path.isfile(x): r = validate(x, schema, quick, settings.deep, settings.stricttextvalidation, settings.warn, settings.debug) else: print("ERROR: File or directory not found: " + x, file=sys.stderr) sys.exit(3) if not r: success = False if not success and not nofail: sys.exit(1) skipnext = False else: print("ERROR: No files specified", file=sys.stderr) sys.exit(2)