def test_ExtractedPlausibleNumberOfExamples(self): example_count = SchemaExamples.count() # for t in api.EXAMPLESMAP: # example_count = example_count + len(t) log.info("Extracted %s examples." % example_count) self.assertTrue( example_count > 200 and example_count < 600, "Expect that we extracted 200 < x < 600 examples from data/*examples.txt. Found: %s " % example_count)
def validate(): COUNT = 0 ERRORCOUNT = 0 SchemaExamples.loadExamplesFiles("default") print("Loaded %d examples " % (SchemaExamples.count())) print("Processing") for ex in SchemaExamples.allExamples(sort=True): if len(EXLIST) == 0 or ex.getKey() in EXLIST: COUNT += 1 if not validateExample(ex): ERRORCOUNT += 1 print ("Processed %s examples %s invalid" % (COUNT,ERRORCOUNT))
#!/usr/bin/env python3 # -*- coding: UTF-8 -*- import sys import os for path in [os.getcwd(), "SchemaExamples"]: sys.path.insert(1, path) #Pickup libs from shipped lib directory import logging logging.basicConfig(level=logging.INFO) # dev_appserver.py --log_level debug . log = logging.getLogger(__name__) from schemaexamples import SchemaExamples, Example SchemaExamples.loadExamplesFiles("default") print("Loaded %d examples " % (SchemaExamples.count())) log.info("Processing") #Example.nextIdReset() changedFiles = [] changedCount = 0 for ex in SchemaExamples.allExamples(sort=True): if not ex.hasValidId(): ex.setKey(Example.nextId()) changedCount += 1 if not ex.getMeta('file') in changedFiles: changedFiles.append(ex.getMeta('file')) filename = ""
def loadExamples(): global LOADEDEXAMPLES if not LOADEDEXAMPLES: SchemaExamples.loadExamplesFiles("default") print("Loaded %d examples " % (SchemaExamples.count()))
from schemaexamples import SchemaExamples, Example exfiles = [] import glob globpatterns = ["data/*examples.txt", "data/ext/*/*examples.txt"] files = [] for g in globpatterns: files.extend(glob.glob(g)) log.info("Loading %d files" % len(files)) for f in files: #log.info("Loading: %s" % f) SchemaExamples.loadExamplesFile(f) log.info("Loaded %s examples" % SchemaExamples.count()) log.info("Processing") #Example.nextIdReset() changedFiles = [] changedCount = 0 for ex in SchemaExamples.allExamples(sort=True): if not ex.hasValidId(): ex.setKey(Example.nextId()) changedCount += 1 if not ex.getMeta('file') in changedFiles: changedFiles.append(ex.getMeta('file')) filename = ""
import sys import os for path in [os.getcwd(),"SchemaExamples"]: sys.path.insert( 1, path ) #Pickup libs from shipped lib directory import logging import argparse logging.basicConfig(level=logging.INFO) # dev_appserver.py --log_level debug . log = logging.getLogger(__name__) from schemaexamples import SchemaExamples, Example parser = argparse.ArgumentParser() parser.add_argument("-o","--output", required=True, help="output file") args = parser.parse_args() SchemaExamples.loadExamplesFiles("default") print("Loaded %d examples " % (SchemaExamples.count())) log.info("Consolidating..") filename = args.output log.info("Writing %s examples to file %s" % (SchemaExamples.count(),filename)) f = open(filename,"w") f.write(SchemaExamples.allExamplesSerialised()) if f: f.close() print("Done")