本文整理汇总了Python中arches.app.models.concept.Concept.traverse方法的典型用法代码示例。如果您正苦于以下问题:Python Concept.traverse方法的具体用法?Python Concept.traverse怎么用?Python Concept.traverse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arches.app.models.concept.Concept
的用法示例。
在下文中一共展示了Concept.traverse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_reference_data
# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import traverse [as 别名]
def import_reference_data(reference_data):
# with transaction.atomic():
# if reference_data != '':
for data in reference_data:
print '\nLOADING {0} CONCEPT SCHEME FROM ARCHES JSON'.format(data['legacyoid'])
print '---------------------------------------------'
def create_collections(concept):
relations = {'':'hasCollection', 'hasTopConcept':'member', 'narrower':'member', 'narrowerTransitive':'member'}
for subconcept in concept.subconcepts:
if concept.relationshiptype in relations.keys():
if concept.id == '00000000-0000-0000-0000-000000000001':
concept.id = '00000000-0000-0000-0000-000000000003'
models.Relation.objects.get_or_create(conceptfrom_id=concept.id, conceptto_id=subconcept.id, relationtype_id=relations[concept.relationshiptype])
concept = Concept(data)
concept.save()
concept.traverse(create_collections, 'down')
concept.index(scheme=concept)
示例2: search
# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import traverse [as 别名]
def search(request):
se = SearchEngineFactory().create()
searchString = request.GET["q"]
removechildren = request.GET.get("removechildren", None)
query = Query(se, start=0, limit=100)
phrase = Match(field="value", query=searchString.lower(), type="phrase_prefix")
query.add_query(phrase)
results = query.search(index="concept_labels")
ids = []
if removechildren != None:
concepts = Concept().get(id=removechildren, include_subconcepts=True, include=None)
def get_children(concept):
ids.append(concept.id)
concepts.traverse(get_children)
newresults = []
cached_scheme_names = {}
for result in results["hits"]["hits"]:
if result["_source"]["conceptid"] not in ids:
# first look to see if we've already retrieved the scheme name
# else look up the scheme name with ES and cache the result
if result["_type"] in cached_scheme_names:
result["in_scheme_name"] = cached_scheme_names[result["_type"]]
else:
query = Query(se, start=0, limit=100)
phrase = Match(field="conceptid", query=result["_type"], type="phrase")
query.add_query(phrase)
scheme = query.search(index="concept_labels")
for label in scheme["hits"]["hits"]:
if label["_source"]["type"] == "prefLabel":
cached_scheme_names[result["_type"]] = label["_source"]["value"]
result["in_scheme_name"] = label["_source"]["value"]
newresults.append(result)
# Use the db to get the concept context but this is SLOW
# for result in results['hits']['hits']:
# if result['_source']['conceptid'] not in ids:
# concept = Concept().get(id=result['_source']['conceptid'], include_parentconcepts=True)
# pathlist = concept.get_paths()
# result['in_scheme_name'] = pathlist[0][0]['label']
# newresults.append(result)
# def crawl(conceptid, path=[]):
# query = Query(se, start=0, limit=100)
# bool = Bool()
# bool.must(Match(field='conceptidto', query=conceptid, type='phrase'))
# bool.must(Match(field='relationtype', query='narrower', type='phrase'))
# query.add_query(bool)
# relations = query.search(index='concept_relations')
# for relation in relations['hits']['hits']:
# path.insert(0, relation)
# crawl(relation['_source']['conceptidfrom'], path=path)
# return path
# for result in results['hits']['hits']:
# if result['_source']['conceptid'] not in ids:
# concept_relations = crawl(result['_source']['conceptid'], path=[])
# if len(concept_relations) > 0:
# conceptid = concept_relations[0]['_source']['conceptidfrom']
# if conceptid in cached_scheme_names:
# result['in_scheme_name'] = cached_scheme_names[conceptid]
# else:
# result['in_scheme_name'] = get_preflabel_from_conceptid(conceptid, lang=settings.LANGUAGE_CODE)['value']
# cached_scheme_names[conceptid] = result['in_scheme_name']
# newresults.append(result)
results["hits"]["hits"] = newresults
return JSONResponse(results)