示例#1
0
def real_evaluate(request):
    # From: http://tools.ietf.org/html/rfc3986#section-2.1
    # gen-delims  = ":" / "/" / "?" / "#" / "[" / "]" / "@"
    # sub-delims  = "!" / "$" / "&" / "'" / "(" / ")"
    #              / "*" / "+" / "," / ";" / "="
    quotesafe = ":/?#[]@!$&'()*+,;=" + "%"
    # isolate parameters (keep invalid URI characters %-encoded)
    RO      = urllib.quote(request.params["RO"], quotesafe)
    minim   = urllib.quote(request.params["minim"], quotesafe)
    target  = urllib.quote(request.params.get("target","."), quotesafe)
    purpose = request.params["purpose"]
    log.info("Evaluate RO %s, minim %s, target %s, purpose %s"%(RO,minim,target,purpose))
    # create rometa object
    # @@TODO: use proper configuration and credentials
    ROparse   = urlparse.urlparse(RO)
    rosrs_uri = (ROparse.scheme or "http") + "://" + (ROparse.netloc or "localhost:8000") + "/"
    ro_config = {
        "annotationTypes":      annotationTypes,
        "annotationPrefixes":   annotationPrefixes,
        "rosrs_uri":            rosrs_uri,
        #"rosrs_uri":            target,
        #"rosrs_uri":            "http://sandbox.wf4ever-project.org/rodl/ROs/",
        #"rosrs_access_token":   "ac14dd1a-ab59-40ec-b510-ffdb01a85473",
        "rosrs_access_token":   None,
        }
    rometa = ro_metadata(ro_config, RO)
    log.info("rometa.rouri: %s"%(rometa.rouri) )
    # invoke evaluation service
    (graph, evalresult) = ro_eval_minim.evaluate(rometa, minim, target, purpose)
    log.debug("evaluate:results: \n"+json.dumps(evalresult, indent=2))
    # Assemble graph of results
    graph =  ro_eval_minim.evalResultGraph(graph, evalresult)
    return graph
示例#2
0
def evaluate(progname, configbase, options, args):
    """
    Evaluate RO

    ro evaluate checklist [ -d <dir> ] <minim> <purpose> [ <target> ]"
    """
    log.debug("evaluate: progname %s, configbase %s, args %s" % 
              (progname, configbase, repr(args)))
    ro_config = getroconfig(configbase, options)
    ro_options = (
        { "rodir":        options.rodir or ""
        , "function":     args[2]
        })
    log.debug("ro_options: " + repr(ro_options))
    ro_ref = ro_root_reference(progname + " annotations", ro_config, None, ro_options['rodir'])
    if not ro_ref: return 1
    # Evaluate...
    if ro_options["function"] == "checklist":
        if len(args) not in [5, 6]:
            print ("%s evaluate checklist: wrong number of arguments provided" % (progname))
            print ("Usage: %s evaluate checklist [ -d <dir> ] [ -a | -l <level> ] <minim> <purpose> [ <target> ]" % (progname))
            return 1
        levels = ["summary", "must", "should", "may", "full"]
        if options.level not in ["summary", "must", "should", "may", "full"]:
            print ("%s evaluate checklist: invalid reporting level %s, must be one of %s" % 
                    (progname, options.level, repr(levels)))
            return 1
        ro_options["minim"]   = ((len(args) > 3) and args[3]) or "minim.rdf"
        ro_options["purpose"] = ((len(args) > 4) and args[4]) or "create"
        ro_options["target"]  = ((len(args) > 5) and args[5]) or "."
        if options.verbose:
            print "ro evaluate %(function)s -d \"%(rodir)s\" %(minim)s %(purpose)s %(target)s" % ro_options
        rometa = ro_metadata(ro_config, ro_ref)
        (minimgraph, evalresult) = ro_eval_minim.evaluate(rometa,
            ro_options["minim"], ro_options["target"], ro_options["purpose"])
        if options.verbose:
            print "== Evaluation result =="
            print json.dumps(evalresult, indent=2)
        if options.outformat and options.outformat.upper() in RDFTYPSERIALIZERMAP:
            # RDF output
            graph = ro_eval_minim.evalResultGraph(minimgraph, evalresult)
            graph.serialize(destination=sys.stdout,
                format=RDFTYPSERIALIZERMAP[options.outformat.upper()])
        else:
            ro_eval_minim.format(evalresult,
                { "detail" : "full" if options.all else options.level },
                sys.stdout)
    # elif ... other functions here
    else:
        print ("%s evaluate: unrecognized function provided (%s)" % (progname, ro_options["function"]))
        print ("Usage:")
        print ("  %s evaluate checklist [ -d <dir> ] [ -a | -l <level> ] <minim> <purpose> [ <target> ]" % (progname))
        return 1
    return 0
 def testEvaluateRDF(self):
     self.setupConfig()
     rodir = self.createTestRo(testbase, "test-chembox", "RO test minim", "ro-testMinim")
     rouri = ro_manifest.getRoUri(rodir)
     self.populateTestRo(testbase, rodir)
     rometa   = ro_metadata(ro_config, rodir)
     resuri   = rometa.getComponentUriAbs("http://purl.org/net/chembox/Ethane")
     reslabel = "Ethane"
     rometa.addGraphAnnotation(resuri, "Ethane.ttl")
     # Now run evaluation against test RO
     (minimgr, evalresult) = ro_eval_minim.evaluate(rometa,
         "Minim-chembox.ttl",                  # Minim file
         resuri,                               # Target resource
         "complete")                           # Purpose
     resultgr = ro_eval_minim.evalResultGraph(minimgr, evalresult)
     log.debug("------ resultgr:\n%s\n----"%(resultgr.serialize(format='turtle'))) # pretty-xml
     ## print "------ resultgr:\n%s\n----"%(resultgr.serialize(format='turtle'))
     # Check response returned
     modeluri = rdflib.URIRef('http://example.com/chembox-samples/minim_model')
     prefixes = make_sparql_prefixes()
     probequeries = (
         [ '''ASK { _:r minim:testedRO <%s> ; minim:minimUri <%s> }'''%
           (rouri, rometa.getComponentUri("Minim-chembox.ttl"))
         , '''ASK { _:r minim:testedRO <%s> ; minim:testedModel <%s> }'''%
           (rouri, modeluri)
         , '''ASK { _:r minim:testedTarget <%s> ; minim:satisfied [ minim:tryMessage "%s" ] }'''%
           (resuri, "InChI identifier is present")
         , '''ASK { _:r minim:testedTarget <%s> ; minim:satisfied [ minim:tryMessage "%s" ] }'''%
           (resuri, "ChemSpider identifier is present")
         , '''ASK { _:r minim:testedTarget <%s> ; minim:missingMay [ minim:tryMessage "%s" ] }'''%
           (resuri, "No synomym is present")
         , '''ASK { _:r minim:testedTarget <%s> ; minim:nominallySatisfies <%s> }'''%
           (resuri, modeluri)
         , '''ASK { _:r minim:testedTarget <%s> ; minim:minimallySatisfies <%s> }'''%
           (resuri, modeluri)
         , '''ASK { <%s> rdfs:label "%s" }'''%
           (resuri, reslabel)
         ])
     for q in probequeries:
         r = resultgr.query(prefixes+q)
         self.assertEqual(r.type, 'ASK', "Result type %s for: %s"%(r.type, q))
         self.assertTrue(r.askAnswer, "Failed query: %s"%(q))
     self.deleteTestRo(rodir)
     return