当前位置: 首页>>代码示例>>Python>>正文


Python ProvBundle.from_provjson方法代码示例

本文整理汇总了Python中prov.model.ProvBundle.from_provjson方法的典型用法代码示例。如果您正苦于以下问题:Python ProvBundle.from_provjson方法的具体用法?Python ProvBundle.from_provjson怎么用?Python ProvBundle.from_provjson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在prov.model.ProvBundle的用法示例。


在下文中一共展示了ProvBundle.from_provjson方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_merging_records_json

# 需要导入模块: from prov.model import ProvBundle [as 别名]
# 或者: from prov.model.ProvBundle import from_provjson [as 别名]
 def test_merging_records_json(self):
     test_json = """
     {
         "entity": {
             "e1": [
                 {"prov:label": "First instance of e1"},
                 {"prov:label": "Second instance of e1"}
             ]
         },
         "activity": {
             "a1": [
                 {"prov:label": "An activity with no time (yet)"},
                 {"prov:startTime": "2011-11-16T16:05:00"},
                 {"prov:endTime": "2011-11-16T16:06:00"}
             ]
         }
     }"""
     g = ProvBundle.from_provjson(test_json)
     e1 = g.get_record("e1")
     self.assertEqual(
         len(e1.get_attribute("prov:label")), 2, "e1 was not merged correctly, expecting two prov:label attributes"
     )
     a1 = g.get_record("a1")
     self.assertIsNotNone(a1.get_startTime(), "a1 was not merged correctly, expecting startTime set.")
     self.assertIsNotNone(a1.get_endTime(), "a1 was not merged correctly, expecting startTime set.")
     self.assertEqual(
         len(a1.get_attribute("prov:label")), 1, "a1 was not merged correctly, expecting one prov:label attribute"
     )
开发者ID:jdcourcol,项目名称:prov,代码行数:30,代码来源:testModel.py

示例2: create

# 需要导入模块: from prov.model import ProvBundle [as 别名]
# 或者: from prov.model.ProvBundle import from_provjson [as 别名]
def create(request):
    if request.method == 'POST':
        if 'convert' in request.POST or 'randomize' in request.POST:
            graphml_str = request.POST["graphml"]
            filename = request.POST["filename"]
            provn_str, output = convert_graphml_string(graphml_str)
            output_list = output.splitlines()
            output_list.sort()
 
            valid, validation_url = validate(provn_str)
            if valid:
                json_str = provn_str.get_provjson()
            else:
                json_str={}
                
            if 'randomize' in request.POST:
                json_str = json.dumps(get_random_graph(json.loads(json_str)))
            
            return render_to_response('provmanager/create.html', {"output_list":output_list, "filename":filename, "graphml_str": graphml_str, "json_str": json_str, "valid":valid, "validation_url":validation_url}, context_instance=RequestContext(request))

        elif 'save' in request.POST:
            graphml_str = request.POST["graphml"]
            provn_str, output = convert_graphml_string(graphml_str)
            valid, validation_url = validate(provn_str)
            if valid:
                name = request.POST["filename"]
                if name=="":
                    name = "PLEASE ENTER A NAME"
                
                inconsistencies_list, clean_graph = get_inconsistencies(json.loads(provn_str.get_provjson()))

                if inconsistencies_list:
                    attribute1 = json.dumps(inconsistencies_list[0])
                    attribute2 = json.dumps(inconsistencies_list[1])
                    type = Provenance.TYPE_CRON
                else:
                    attribute1 = None
                    attribute2 = None
                    #TODO: is there a better way to check the type?
                    #if there are no inconsistencies, then we assume it is a MOP_TEMPLATE provenance document
                    type = Provenance.TYPE_MOP_TEMPLATE
  
                bundle = ProvBundle.from_provjson(json.dumps(clean_graph))
                
                store_id = API.submit_document(bundle, name, public=False)

                provenance = Provenance(name=name, store_id=store_id, attribute1=attribute1, attribute2=attribute2, type=type)
                provenance.save()
                return HttpResponseRedirect(reverse('provmanager_index'))
            
            
    return render_to_response('provmanager/create.html', context_instance=RequestContext(request))
开发者ID:pombredanne,项目名称:deptx,代码行数:54,代码来源:views.py

示例3: testAllExamples

# 需要导入模块: from prov.model import ProvBundle [as 别名]
# 或者: from prov.model.ProvBundle import from_provjson [as 别名]
 def testAllExamples(self):
     num_graphs = len(examples.tests)
     logger.info('Testing %d provenance graphs' % num_graphs)
     counter = 0
     for name, graph in examples.tests:
         counter += 1
         logger.info('%d. Testing the %s example' % (counter, name))
         g1 = graph()
         logger.debug('Original graph in PROV-N\n%s' % g1.get_provn())
         json_str = g1.get_provjson(indent=4)
         logger.debug('Original graph in PROV-JSON\n%s' % json_str)
         g2 = ProvBundle.from_provjson(json_str)
         logger.debug('Graph decoded from PROV-JSON\n%s' % g2.get_provn())
         self.assertEqual(g1, g2, 'Round-trip JSON encoding/decoding failed:  %s.' % name)
开发者ID:pombredanne,项目名称:prov,代码行数:16,代码来源:testModel.py

示例4: testLoadAllJSON

# 需要导入模块: from prov.model import ProvBundle [as 别名]
# 或者: from prov.model.ProvBundle import from_provjson [as 别名]
 def testLoadAllJSON(self):
     json_path = os.path.dirname(os.path.abspath(__file__)) + '/json/'
     filenames = os.listdir(json_path)
     fails = []
     for filename in filenames:
         if filename.endswith('.json'):
             with open(json_path + filename) as json_file:
                 try:
                     g1 = json.load(json_file, cls=ProvBundle.JSONDecoder)
                     json_str = g1.get_provjson(indent=4)
                     g2 = ProvBundle.from_provjson(json_str)
                     self.assertEqual(g1, g2, 'Round-trip JSON encoding/decoding failed:  %s.' % filename)
                 except:
                     fails.append(filename)
     self.assertFalse(fails, 'Failed to load %d JSON files (%s)' % (len(fails), ', '.join(fails)))
开发者ID:pombredanne,项目名称:prov,代码行数:17,代码来源:testModel.py

示例5: test_datetime_with_tz

# 需要导入模块: from prov.model import ProvBundle [as 别名]
# 或者: from prov.model.ProvBundle import from_provjson [as 别名]
 def test_datetime_with_tz(self):
     """ test that timezone is taken in to account while parsing json"""
     test_json = """
     {
         "activity": {
             "a1": [
                 {"prov:label": "An activity with timezone"},
                 {"prov:startTime": "2011-11-16T16:05:00.123456+03:00"},
                 {"prov:endTime": "2011-11-16T16:06:00.654321"}
             ]
         }
     }"""
     g = ProvBundle.from_provjson(test_json)
     a1 = g.get_record("a1")
     self.assertEqual(
         a1.get_startTime().isoformat(), "2011-11-16T16:05:00.123456+03:00", "timezone is not set correctly"
     )
     self.assertEqual(a1.get_endTime().isoformat(), "2011-11-16T16:06:00.654321", "timezone is not set correctly")
开发者ID:jdcourcol,项目名称:prov,代码行数:20,代码来源:testModel.py

示例6: randomize_document

# 需要导入模块: from prov.model import ProvBundle [as 别名]
# 或者: from prov.model.ProvBundle import from_provjson [as 别名]
def randomize_document(mopDocument):
    #bundle = API.get_document(task.provenance.store_id)
    #TODO randomize provn/json
    json_graph = getProvJson(mopDocument.provenance)
    random_graph = get_random_graph(json_graph)
    inconsistencies_list, clean_graph = get_inconsistencies(random_graph)

    attribute1 = json.dumps(inconsistencies_list[0])
    attribute2 = json.dumps(inconsistencies_list[1])

    bundle = ProvBundle.from_provjson(json.dumps(clean_graph))
    name = "%s (randomized)" % (mopDocument.provenance.name)
    store_id = API.submit_document(bundle, name, public=False)
    provenance = Provenance(name=name, store_id=store_id, attribute1=attribute1, attribute2=attribute2, type=Provenance.TYPE_MOP_INSTANCE)
    provenance.save()
        
    randomizedDocument = RandomizedDocument.objects.create(mopDocument=mopDocument, provenance=provenance)
    return randomizedDocument
开发者ID:pombredanne,项目名称:deptx,代码行数:20,代码来源:views.py

示例7: create

# 需要导入模块: from prov.model import ProvBundle [as 别名]
# 或者: from prov.model.ProvBundle import from_provjson [as 别名]
def create(request):
    if request.method == 'POST':
        if 'convertMop' in request.POST or 'convertCron' in request.POST or 'randomize' in request.POST:
            if 'convertCron' in request.POST:
                isCron = True
                isMop = False
            else:
                isCron = False
                isMop = True
            #graphml_str = request.POST["graphml"]
            filename, graphml_str = getStuff(request)
            
            
            provn_str, output = convert_graphml_string(graphml_str)
            output_list = output.splitlines()
            output_list.sort()

            valid = True
            validation_url = "bla"
            #valid, validation_url = validate(provn_str)
            if valid:
                json_str = provn_str.get_provjson()
            else:
                json_str={}
            
            #print json_str
                
            inconsistencies_list = None
            spoilers = False
            if 'randomize' in request.POST:
                print request.POST
                random_graph = get_random_graph(json.loads(json_str))
                json_str = json.dumps(random_graph)
                inconsistencies_list, clean_graph = get_inconsistencies(random_graph)
                if 'spoilers' in request.POST: 
                    spoilers = True
                else:
                    spoilers = False
                    json_str = json.dumps(clean_graph)
                print spoilers
                
                
            return render(request, 'provmanager/create.html', {"inconsistencies_list":inconsistencies_list, "spoilers":spoilers, "output_list":output_list, "filename":filename, "json_str": json_str, "isMop":isMop, "isCron":isCron, "valid":valid, "validation_url":validation_url})

        elif 'saveMop' in request.POST or 'saveCron' in request.POST:
            if 'saveCron' in request.POST:
                type = Provenance.TYPE_CRON
            else:
                type = Provenance.TYPE_MOP_TEMPLATE
            
            filename, graphml_str = getStuff(request)
            provn_str, output = convert_graphml_string(graphml_str)
            
            valid = True
            validation_url = "bla"
            #valid, validation_url = validate(provn_str)
            if valid:
                name = request.POST["filename"]
                if name=="":
                    name = "PLEASE ENTER A NAME"
                
                inconsistencies_list, clean_graph = get_inconsistencies(json.loads(provn_str.get_provjson()))

                if inconsistencies_list:
                    attribute1 = json.dumps(inconsistencies_list[0])
                    attribute2 = json.dumps(inconsistencies_list[1])
                else:
                    attribute1 = None
                    attribute2 = None
  
                bundle = ProvBundle.from_provjson(json.dumps(clean_graph))
                
                store_id = API.submit_document(bundle, name, public=False)

                provenance = Provenance(name=name, store_id=store_id, attribute1=attribute1, attribute2=attribute2, type=type)
                provenance.save()
                return HttpResponseRedirect(reverse('provmanager_index'))
            
    try:
        filename = request.session['filename']
    except:
        filename = ""      
    return render(request, 'provmanager/create.html', {"filename":filename})
开发者ID:bachour,项目名称:deptx,代码行数:85,代码来源:views.py


注:本文中的prov.model.ProvBundle.from_provjson方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。