示例#1
0
def validate(filename, schema = None):            
    try:
        folia.validate(filename, schema)
    except Exception as e:
        print >>sys.stderr, "VALIDATION ERROR in " + filename
        print >>sys.stderr, str(e)
        return False
    print >>sys.stderr, "Validated succesfully: " +  filename
    return True
示例#2
0
def validate(filepath):
    global schema
    print "\tValidating"
    try:
        folia.validate(filepath, schema)
        print "\t\tSuccess"
    except Exception, e:
        errout("\t\tERROR: DOCUMENT DOES NOT VALIDATE! (" + filepath + "): " +
               str(e))
示例#3
0
def validate(filename, schema=None):
    try:
        folia.validate(filename, schema)
    except Exception as e:
        print >> sys.stderr, "VALIDATION ERROR in " + filename
        print >> sys.stderr, str(e)
        return False
    print >> sys.stderr, "Validated succesfully: " + filename
    return True
示例#4
0
def validate(filename, schema = None, quick=False):
    try:
        folia.validate(filename, schema)
    except Exception as e:
        print("VALIDATION ERROR against RelaxNG schema (stage 1/2), in " + filename,file=sys.stderr)
        print(str(e), file=sys.stderr)
        return False
    try:
        folia.Document(file=filename)
    except Exception as e:
        print("VALIDATION ERROR on full parse by library (stage 2/2), in " + filename,file=sys.stderr)
        print(e.__class__.__name__ + ": " + str(e),file=sys.stderr)
        print("Full traceback follows:",file=sys.stderr)
        ex_type, ex, tb = sys.exc_info()
        traceback.print_tb(tb)
        return False

    print("Validated successfully: " +  filename,file=sys.stderr)
    return True
示例#5
0
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
    
    Licensed under the GNU General Public License v3
-->
""" %  (folia.FOLIAVERSION, folia.LIBVERSION))
codecs.open('folia.rng','w','utf-8').writelines(data)


print "Validating example document"
folia.validate('../test/example.xml')
示例#6
0
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)

    Validation examples:
     $ xmllint ‒‒relaxng folia.rng foliadocument.xml
     $ jing folia.rng foliadocument.xml

    However, it is recommended to use the foliavalidator tool instead,
    as it does extra validation that can not be captured by RelaxNG!

    $ foliavalidator foliadocument.xml

    Licensed under the GNU General Public License v3
-->
""" % (folia.FOLIAVERSION, folia.LIBVERSION))
io.open('folia.rng', 'w', encoding='utf-8').writelines(data)

print("Validating example document")
folia.validate('../test/example.xml')
示例#7
0
def validate(filename,
             schema=None,
             quick=False,
             deep=False,
             stricttextvalidation=False,
             warn=True,
             debug=False):
    try:
        folia.validate(filename, schema)
    except Exception as e:
        print("VALIDATION ERROR against RelaxNG schema (stage 1/2), in " +
              filename,
              file=sys.stderr)
        print(str(e), file=sys.stderr)
        return False
    try:
        document = folia.Document(file=filename,
                                  deepvalidation=deep,
                                  textvalidation=True,
                                  verbose=True,
                                  debug=debug)
    except folia.DeepValidationError as e:
        print(
            "DEEP VALIDATION ERROR on full parse by library (stage 2/2), in " +
            filename,
            file=sys.stderr)
        print(e.__class__.__name__ + ": " + str(e), file=sys.stderr)
        return False
    except Exception as e:
        print("VALIDATION ERROR on full parse by library (stage 2/2), in " +
              filename,
              file=sys.stderr)
        print(e.__class__.__name__ + ": " + str(e), file=sys.stderr)
        print("-- Full traceback follows -->", file=sys.stderr)
        ex_type, ex, tb = sys.exc_info()
        traceback.print_exception(ex_type, ex, tb)
        return False
    if not document.version:
        print("VALIDATION ERROR: Document does not advertise FoLiA version (" +
              filename + ")",
              file=sys.stderr)
        return False
    elif folia.checkversion(document.version) == -1 and warn:
        print(
            "WARNING: Document (" + filename +
            ") uses an older FoLiA version (" + document.version +
            ") but is validated according to the newer specification (" +
            folia.FOLIAVERSION +
            "). You might want to increase the version attribute if this is a document you created and intend to publish.",
            file=sys.stderr)
    if document.textvalidationerrors:
        if stricttextvalidation:
            print("VALIDATION ERROR because of text validation errors, in " +
                  filename,
                  file=sys.stderr)
            return False
        elif warn:
            print(
                "WARNING: there were " + str(document.textvalidationerrors) +
                " text validation errors but these are currently not counted toward the full validation result (use -t for strict text validation)",
                file=sys.stderr)

    print("Validated successfully: " + filename, file=sys.stderr)
    return True