Beispiel #1
0
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))
Beispiel #2
0
    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)
Beispiel #3
0
def buildTerms(terms):
    all = ["ALL", "All", "all"]
    for a in all:
        if a in terms:
            terms = SdoTermSource.getAllTerms(supressSourceLinks=True)
            break
    import time, datetime
    start = datetime.datetime.now()
    lastCount = 0
    if len(terms):
        print("\nBuilding term pages...\n")
    for t in terms:
        tic = datetime.datetime.now()  #diagnostics
        term = SdoTermSource.getTerm(t, expanded=True)
        if not term:
            print("No such term: %s\n" % t)
            continue

        if term.termType == SdoTerm.REFERENCE:  #Don't create pages for reference types
            continue
        examples = SchemaExamples.examplesForTerm(term.id)
        pageout = termtemplateRender(term, examples)
        f = open(termFileName(term.id), "w")
        f.write(pageout)
        f.close()

        #diagnostics ##########################################
        termsofar = len(SdoTermSource.termCache())  #diagnostics
        termscreated = termsofar - lastCount  #diagnostics
        lastCount = termsofar  #diagnostics
        print("Term: %s (%d) - %s" %
              (t, termscreated,
               str(datetime.datetime.now() - tic)))  #diagnostics
        #      Note: (%d) = number of individual newly created (not cached) term definitions to
        #            build this expanded definition. ie. All Properties associated with a Type, etc.

    if len(terms):
        print()
        print("All terms took %s seconds" %
              str(datetime.datetime.now() - start))  #diagnostics
#!/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 = ""
Beispiel #5
0
# -*- 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 Example, SchemaExamples
"""
Load examples from file
write back to another file
"""

SchemaExamples.loadExamplesFile("data/ext/pending/issue-894-examples.txt")
#print(SchemaExamples.examplesForTerm("Event"))

#filename = "out" + term.id +".html"
filename = "SchemaExamples/example-code/out"

exes = sorted(SchemaExamples.allExamples(),
              key=lambda x: (x.exmeta['file'], x.exmeta['filepos']))
f = open(filename, "w")
for ex in exes:
    f.write(ex.serialize())
    f.write("\n")
f.close()
Beispiel #6
0
schema_path = './data/schema.ttl'
examples_path = './data/examples.txt'

andstr = "\n AND\n  "
TYPECOUNT_UPPERBOUND = 1500
TYPECOUNT_LOWERBOUND = 500

logging.basicConfig(level=logging.INFO)
log = logging.getLogger(__name__)

SdoTermSource.loadSourceGraph("default")
print("loaded %s triples - %s terms" %
      (len(SdoTermSource.sourceGraph()), len(SdoTermSource.getAllTerms())))

print("Loading examples files")
SchemaExamples.loadExamplesFiles("default")
print("Loaded %d examples" % SchemaExamples.count())

# Tests to probe the health of both schemas and code.
# Note that known failings can be annotated with @unittest.expectedFailure or @skip("reason...")


class BallparkCountTests(unittest.TestCase):
    def test_alltypes(self):

        # ballpark estimates.
        self.assertTrue(
            len(SdoTermSource.getAllTypes()) > TYPECOUNT_LOWERBOUND,
            "Should be > %d types. Got %s" %
            (TYPECOUNT_LOWERBOUND, len(SdoTermSource.getAllTypes())))
        self.assertTrue(
Beispiel #7
0
def loadExamples():
    global LOADEDEXAMPLES
    if not LOADEDEXAMPLES:
        SchemaExamples.loadExamplesFiles("default")
        print("Loaded %d examples " % (SchemaExamples.count()))
Beispiel #8
0
#!/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 Example, SchemaExamples
"""
Load examples from file
"""
import glob
globpatterns = ["data/*examples.txt", "data/ext/*/*examples.txt"]

files = []
for g in globpatterns:
    files.extend(glob.glob(g))

print("Loading %d files" % len(files))
SchemaExamples.loadExamplesFiles(files)

for term in ["CreativeWork", "Person", "Atlas", "DefinedTerm"]:
    for ex in SchemaExamples.examplesForTerm(term):
        print("%s has example key: %s" % (term, ex.getKey()))
log = logging.getLogger(__name__)

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'))
Beispiel #10
0
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")