本文整理汇总了Python中arches.app.models.concept.Concept.save方法的典型用法代码示例。如果您正苦于以下问题:Python Concept.save方法的具体用法?Python Concept.save怎么用?Python Concept.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arches.app.models.concept.Concept
的用法示例。
在下文中一共展示了Concept.save方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: manage_parents
# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import save [as 别名]
def manage_parents(request, conceptid):
# need to check user credentials here
if request.method == "POST":
json = request.body
if json != None:
data = JSONDeserializer().deserialize(json)
with transaction.atomic():
if len(data["deleted"]) > 0:
concept = Concept({"id": conceptid})
for deleted in data["deleted"]:
concept.addparent(deleted)
concept.delete()
if len(data["added"]) > 0:
concept = Concept({"id": conceptid})
for added in data["added"]:
concept.addparent(added)
concept.save()
return JSONResponse(data)
else:
return HttpResponseNotAllowed(["POST"])
return HttpResponseNotFound()
示例2: test_create_concept
# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import save [as 别名]
def test_create_concept(self):
"""
Test of basic CRUD on a Concept model
"""
concept_in = Concept()
concept_in.nodetype = 'Concept'
concept_in.values = [ConceptValue({
#id: '',
#conceptid: '',
'type': 'prefLabel',
'category': 'label',
'value': 'test pref label',
'language': 'en-US'
})]
concept_in.save()
concept_out = Concept().get(id=concept_in.id)
self.assertEqual(concept_out.id, concept_in.id)
self.assertEqual(concept_out.values[0].value, 'test pref label')
label = concept_in.values[0]
label.value = 'updated pref label'
concept_in.values[0] = label
concept_in.save()
concept_out = Concept().get(id=concept_in.id)
self.assertEqual(concept_out.values[0].value, 'updated pref label')
concept_out.delete(delete_self=True)
with self.assertRaises(models.Concept.DoesNotExist):
deleted_concept = Concept().get(id=concept_out.id)
示例3: add_concepts_from_sparql_endpoint
# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import save [as 别名]
def add_concepts_from_sparql_endpoint(request, conceptid):
if request.method == "POST":
json = request.body
if json != None:
data = JSONDeserializer().deserialize(json)
parentconcept = Concept({"id": conceptid, "nodetype": data["model"]["nodetype"]})
if parentconcept.nodetype == "Concept":
relationshiptype = "narrower"
elif parentconcept.nodetype == "ConceptScheme":
relationshiptype = "hasTopConcept"
provider = get_sparql_providers(data["endpoint"])
try:
parentconcept.subconcepts = provider.get_concepts(data["ids"])
except Exception as e:
return HttpResponseServerError(e.message)
for subconcept in parentconcept.subconcepts:
subconcept.relationshiptype = relationshiptype
parentconcept.save()
parentconcept.index()
return JSONResponse(parentconcept, indent=4)
else:
return HttpResponseNotAllowed(["POST"])
return HttpResponseNotFound()
示例4: add_concepts_from_sparql_endpoint
# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import save [as 别名]
def add_concepts_from_sparql_endpoint(request, conceptid):
if request.method == 'POST':
json = request.body
if json != None:
data = JSONDeserializer().deserialize(json)
parentconcept = Concept({
'id': conceptid,
'nodetype': data['model']['nodetype']
})
if parentconcept.nodetype == 'Concept':
relationshiptype = 'narrower'
elif parentconcept.nodetype == 'ConceptScheme':
relationshiptype = 'hasTopConcept'
provider = get_sparql_providers(data['endpoint'])
try:
parentconcept.subconcepts = provider.get_concepts(data['ids'])
except Exception as e:
return HttpResponseServerError(e.message)
for subconcept in parentconcept.subconcepts:
subconcept.relationshiptype = relationshiptype
parentconcept.save()
parentconcept.index()
return JSONResponse(parentconcept, indent=4)
else:
return HttpResponseNotAllowed(['POST'])
return HttpResponseNotFound()
示例5: manage_parents
# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import save [as 别名]
def manage_parents(request, conceptid):
if request.method == 'POST':
json = request.body
if json != None:
data = JSONDeserializer().deserialize(json)
with transaction.atomic():
if len(data['deleted']) > 0:
concept = Concept().get(id=conceptid, include=None)
for deleted in data['deleted']:
concept.addparent(deleted)
concept.delete()
concept.bulk_index()
if len(data['added']) > 0:
concept = Concept().get(id=conceptid)
for added in data['added']:
concept.addparent(added)
concept.save()
concept.bulk_index()
return JSONResponse(data)
else:
return HttpResponseNotAllowed(['POST'])
return HttpResponseNotFound()
示例6: import_concepts
# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import save [as 别名]
def import_concepts(reference_data):
concepts = reference_data[0]['concepts']
values = reference_data[1]['values']
relations = reference_data[2]['relations']
concept_objs = {}
for concept in concepts:
concept_obj = Concept()
concept_obj.id = concept['conceptid']
concept_obj.nodetype = concept['nodetype']
concept_obj.legacyoid = concept['legacyoid']
concept_obj.save()
concept_objs[concept_obj.id] = concept_obj
existing_valuetypes = [o.valuetype for o in models.DValueType.objects.all()]
for value in values:
if value['valuetype'] not in existing_valuetypes:
models.DValueType.objects.create(valuetype = value['valuetype'], category = 'undefined', namespace = 'arches')
existing_valuetypes.append(value['valuetype'])
conceptvalue_obj = ConceptValue()
conceptvalue_obj.id = value['valueid']
conceptvalue_obj.conceptid = value['conceptid']
conceptvalue_obj.type = value['valuetype']
conceptvalue_obj.value = value['value']
conceptvalue_obj.language = value['languageid']
conceptvalue_obj.save()
for relation in relations:
if relation['conceptidfrom'] in concept_objs and relation['conceptidto'] in concept_objs:
conceptfrom = concept_objs[relation['conceptidfrom']]
conceptto = concept_objs[relation['conceptidto']]
conceptfrom.add_relation(conceptto, relation['relationtype'])
示例7: import_reference_data
# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import save [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)
示例8: concept
# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import save [as 别名]
#.........这里部分代码省略.........
"concept": concept_graph,
"languages": languages,
"valuetype_labels": valuetypes.filter(category="label"),
"valuetype_notes": valuetypes.filter(category="note"),
"valuetype_related_values": valuetypes.filter(category="undefined"),
"related_relations": relationtypes.filter(relationtype="member"),
"concept_paths": concept_graph.get_paths(lang=lang),
},
context_instance=RequestContext(request),
)
concept_graph = Concept().get(
id=conceptid,
include_subconcepts=include_subconcepts,
include_parentconcepts=include_parentconcepts,
include_relatedconcepts=include_relatedconcepts,
depth_limit=depth_limit,
up_depth_limit=None,
lang=lang,
)
if f == "skos":
include_parentconcepts = False
include_subconcepts = True
depth_limit = None
skos = SKOSWriter()
return HttpResponse(skos.write(concept_graph, format="pretty-xml"), content_type="application/xml")
if emulate_elastic_search:
ret.append({"_type": id, "_source": concept_graph})
else:
ret.append(concept_graph)
if emulate_elastic_search:
ret = {"hits": {"hits": ret}}
return JSONResponse(ret, indent=4 if pretty else None)
if request.method == "POST":
if len(request.FILES) > 0:
skosfile = request.FILES.get("skosfile", None)
imagefile = request.FILES.get("file", None)
if imagefile:
value = models.FileValues(
valueid=str(uuid.uuid4()),
value=request.FILES.get("file", None),
conceptid_id=conceptid,
valuetype_id="image",
languageid_id=settings.LANGUAGE_CODE,
)
value.save()
return JSONResponse(value)
elif skosfile:
skos = SKOSReader()
rdf = skos.read_file(skosfile)
ret = skos.save_concepts_from_skos(rdf)
return JSONResponse(ret)
else:
data = JSONDeserializer().deserialize(request.body)
if data:
with transaction.atomic():
concept = Concept(data)
concept.save()
concept.index()
return JSONResponse(concept)
if request.method == "DELETE":
data = JSONDeserializer().deserialize(request.body)
if data:
with transaction.atomic():
concept = Concept(data)
delete_self = data["delete_self"] if "delete_self" in data else False
if not (delete_self and concept.id in CORE_CONCEPTS):
in_use = False
if delete_self:
check_concept = Concept().get(data["id"], include_subconcepts=True)
in_use = check_concept.check_if_concept_in_use()
if "subconcepts" in data:
for subconcept in data["subconcepts"]:
if in_use == False:
check_concept = Concept().get(subconcept["id"], include_subconcepts=True)
in_use = check_concept.check_if_concept_in_use()
if in_use == False:
concept.delete_index(delete_self=delete_self)
concept.delete(delete_self=delete_self)
else:
return JSONResponse({"in_use": in_use})
return JSONResponse(concept)
return HttpResponseNotFound
示例9: create_reference_data
# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import save [as 别名]
def create_reference_data(new_concepts, create_collections):
errors = []
candidates = Concept().get(id='00000000-0000-0000-0000-000000000006')
for arches_nodeid, concepts in new_concepts.iteritems():
collectionid = str(uuid.uuid4())
topconceptid = str(uuid.uuid4())
node = Node.objects.get(nodeid=arches_nodeid)
# if node.datatype is concept or concept-list create concepts and collections
if node.datatype in ['concept', 'concept-list']:
# create collection if create_collections = create, otherwise append to collection already assigned to node
if create_collections == True:
collection_legacyoid = node.name + '_' + str(node.graph_id) + '_import'
# check to see that there is not already a collection for this node
if node.config['rdmCollection'] != None:
errors.append({'type': 'WARNING', 'message': 'A collection already exists for the {0} node. Use the add option to add concepts to this collection.'.format(node.name)})
if len(errors) > 0:
self.errors += errors
collection = None
else:
# if there is no collection assigned to this node, create one and assign it to the node
try:
# check to see that a collection with this legacyid does not already exist
collection = Concept().get(legacyoid=collection_legacyoid)
errors.append({'type': 'WARNING', 'message': 'A collection with the legacyid {0} already exists.'.format(node.name + '_' + str(node.graph_id) + '_import')})
if len(errors) > 0:
self.errors += errors
except:
collection = Concept({
'id': collectionid,
'legacyoid': collection_legacyoid,
'nodetype': 'Collection'
})
collection.addvalue({'id': str(uuid.uuid4()), 'value': node.name + '_import', 'language': settings.LANGUAGE_CODE, 'type': 'prefLabel'})
node.config['rdmCollection'] = collectionid
node.save()
collection.save()
else:
# if create collection = add check that there is a collection associated with node, if no collection associated with node create a collection and associated with the node
try:
collection = Concept().get(id=node.config['rdmCollection'])
except:
collection = Concept({
'id': collectionid,
'legacyoid': node.name + '_' + str(node.graph_id) + '_import',
'nodetype': 'Collection'
})
collection.addvalue({'id': str(uuid.uuid4()), 'value': node.name + '_import', 'language': settings.LANGUAGE_CODE, 'type': 'prefLabel'})
node.config['rdmCollection'] = collectionid
node.save()
collection.save()
if collection != None:
topconcept_legacyoid = node.name + '_' + str(node.graph_id)
# Check if top concept already exists, if not create it and add to candidates scheme
try:
topconcept = Concept().get(legacyoid=topconcept_legacyoid)
except:
topconcept = Concept({
'id': topconceptid,
'legacyoid': topconcept_legacyoid,
'nodetype': 'Concept'
})
topconcept.addvalue({'id': str(uuid.uuid4()), 'value': node.name + '_import', 'language': settings.LANGUAGE_CODE, 'type': 'prefLabel'})
topconcept.save()
candidates.add_relation(topconcept, 'narrower')
# create child concepts and relate to top concept and collection accordingly
for conceptid, value in concepts.iteritems():
concept_legacyoid = value + '_' + node.name + '_' + str(node.graph_id)
# check if concept already exists, if not create and add to topconcept and collection
try:
conceptid = [concept for concept in topconcept.get_child_concepts(topconcept.id) if concept[1] == value][0][0]
concept = Concept().get(id=conceptid)
except:
concept = Concept({
'id': conceptid,
'legacyoid': concept_legacyoid,
'nodetype': 'Concept'
})
concept.addvalue({'id': str(uuid.uuid4()), 'value': value, 'language': settings.LANGUAGE_CODE, 'type': 'prefLabel'})
concept.save()
collection.add_relation(concept, 'member')
topconcept.add_relation(concept, 'narrower')
#if node.datatype is domain or domain-list create options array in node.config
elif node.datatype in ['domain-value', 'domain-value-list']:
for domainid, value in new_concepts[arches_nodeid].iteritems():
# check if value already exists in domain
if value not in [t['text'] for t in node.config['options']]:
domainvalue = {
"text": value,
"selected": False,
"id": domainid
}
node.config['options'].append(domainvalue)
node.save()
示例10: concept
# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import save [as 别名]
#.........这里部分代码省略.........
'valuetype_related_values': valuetypes.filter(category='undefined'),
'parent_relations': parent_relations,
'related_relations': relationtypes.filter(Q(category='Mapping Properties') | Q(relationtype = 'related')),
'concept_paths': concept_graph.get_paths(lang=lang),
'graph_json': JSONSerializer().serialize(concept_graph.get_node_and_links(lang=lang)),
'direct_parents': [parent.get_preflabel(lang=lang) for parent in concept_graph.parentconcepts]
})
else:
return render(request, 'views/rdm/entitytype-report.htm', {
'lang': lang,
'prefLabel': prefLabel,
'labels': labels,
'concept': concept_graph,
'languages': languages,
'valuetype_labels': valuetypes.filter(category='label'),
'valuetype_notes': valuetypes.filter(category='note'),
'valuetype_related_values': valuetypes.filter(category='undefined'),
'related_relations': relationtypes.filter(relationtype = 'member'),
'concept_paths': concept_graph.get_paths(lang=lang)
})
concept_graph = Concept().get(id=conceptid, include_subconcepts=include_subconcepts,
include_parentconcepts=include_parentconcepts, include_relatedconcepts=include_relatedconcepts,
depth_limit=depth_limit, up_depth_limit=None, lang=lang)
if f == 'skos':
include_parentconcepts = False
include_subconcepts = True
depth_limit = None
skos = SKOSWriter()
return HttpResponse(skos.write(concept_graph, format="pretty-xml"), content_type="application/xml")
if emulate_elastic_search:
ret.append({'_type': id, '_source': concept_graph})
else:
ret.append(concept_graph)
if emulate_elastic_search:
ret = {'hits':{'hits':ret}}
return JSONResponse(ret, indent=4 if pretty else None)
if request.method == 'POST':
if len(request.FILES) > 0:
skosfile = request.FILES.get('skosfile', None)
imagefile = request.FILES.get('file', None)
if imagefile:
value = models.FileValue(valueid = str(uuid.uuid4()), value = request.FILES.get('file', None), conceptid_id = conceptid, valuetype_id = 'image',languageid_id = settings.LANGUAGE_CODE)
value.save()
return JSONResponse(value)
elif skosfile:
skos = SKOSReader()
rdf = skos.read_file(skosfile)
ret = skos.save_concepts_from_skos(rdf)
return JSONResponse(ret)
else:
data = JSONDeserializer().deserialize(request.body)
if data:
with transaction.atomic():
concept = Concept(data)
concept.save()
concept.index()
return JSONResponse(concept)
if request.method == 'DELETE':
data = JSONDeserializer().deserialize(request.body)
if data:
with transaction.atomic():
concept = Concept(data)
delete_self = data['delete_self'] if 'delete_self' in data else False
if not (delete_self and concept.id in CORE_CONCEPTS):
in_use = False
if delete_self:
check_concept = Concept().get(data['id'], include_subconcepts=True)
in_use = check_concept.check_if_concept_in_use()
if 'subconcepts' in data:
for subconcept in data['subconcepts']:
if in_use == False:
check_concept = Concept().get(subconcept['id'], include_subconcepts=True)
in_use = check_concept.check_if_concept_in_use()
if in_use == False:
concept.delete_index(delete_self=delete_self)
concept.delete(delete_self=delete_self)
else:
return JSONResponse({"in_use": in_use})
return JSONResponse(concept)
return HttpResponseNotFound
示例11: load_authority_file
# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import save [as 别名]
def load_authority_file(cursor, path_to_authority_files, filename, auth_file_to_entity_concept_mapping):
print filename.upper()
start = time()
value_types = models.DValueType.objects.all()
filepath = os.path.join(path_to_authority_files, filename)
unicodecsv.field_size_limit(sys.maxint)
errors = []
lookups = Lookups()
#create nodes for each authority document file and relate them to the authority document node in the concept schema
auth_doc_file_name = str(filename)
display_file_name = string.capwords(auth_doc_file_name.replace('_',' ').replace('AUTHORITY DOCUMENT.csv', '').strip())
if auth_doc_file_name.upper() != 'ARCHES RESOURCE CROSS-REFERENCE RELATIONSHIP TYPES.E32.CSV':
top_concept = Concept()
top_concept.id = str(uuid.uuid4())
top_concept.nodetype = 'Concept'
top_concept.legacyoid = auth_doc_file_name
top_concept.addvalue({'value':display_file_name, 'language': settings.LANGUAGE_CODE, 'type': 'prefLabel', 'category': 'label'})
lookups.add_relationship(source='00000000-0000-0000-0000-000000000001', type='hasTopConcept', target=top_concept.id)
collector_concept = Concept()
collector_concept.id = str(uuid.uuid4())
collector_concept.nodetype = 'Collection'
collector_concept.legacyoid = auth_doc_file_name.split('.')[0]
collector_concept.addvalue({'value':display_file_name, 'language': settings.LANGUAGE_CODE, 'type': 'prefLabel', 'category': 'label'})
collector_concept.save()
lookups.add_relationship(source='00000000-0000-0000-0000-000000000003', type='hasCollection', target=collector_concept.id)
else:
top_concept = Concept().get(id = '00000000-0000-0000-0000-000000000005')
top_concept.legacyoid = 'ARCHES RESOURCE CROSS-REFERENCE RELATIONSHIP TYPES.E32.csv'
lookups.add_lookup(concept=top_concept, rownum=0)
try:
with open(filepath, 'rU') as f:
rows = unicodecsv.DictReader(f, fieldnames=['CONCEPTID','PREFLABEL','ALTLABELS','PARENTCONCEPTID','CONCEPTTYPE','PROVIDER'],
encoding='utf-8-sig', delimiter=',', restkey='ADDITIONAL', restval='MISSING')
rows.next() # skip header row
for row in rows:
try:
if 'MISSING' in row:
raise Exception('The row wasn\'t parsed properly. Missing %s' % (row['MISSING']))
else:
legacyoid = row[u'CONCEPTID']
concept = Concept()
concept.id = legacyoid if is_uuid(legacyoid) == True else str(uuid.uuid4())
concept.nodetype = 'Concept'# if row[u'CONCEPTTYPE'].upper() == 'INDEX' else 'Collection'
concept.legacyoid = row[u'CONCEPTID']
concept.addvalue({'value':row[u'PREFLABEL'], 'language': settings.LANGUAGE_CODE, 'type': 'prefLabel', 'category': 'label'})
if row['CONCEPTTYPE'].lower() == 'collector':
concept.addvalue({'value':row[u'PREFLABEL'], 'language': settings.LANGUAGE_CODE, 'type': 'collector', 'category': 'label'})
if row[u'ALTLABELS'] != '':
altlabel_list = row[u'ALTLABELS'].split(';')
for altlabel in altlabel_list:
concept.addvalue({'value':altlabel, 'language': settings.LANGUAGE_CODE, 'type': 'altLabel', 'category': 'label'})
parent_concept_id = lookups.get_lookup(legacyoid=row[u'PARENTCONCEPTID']).id
lookups.add_relationship(source=parent_concept_id, type='narrower', target=concept.id, rownum=rows.line_num)
# don't add a member relationship between a top concept and it's children
# if parent_concept_id != top_concept.id:
lookups.add_relationship(source=parent_concept_id, type='member', target=concept.id, rownum=rows.line_num)
# add the member relationship from the authority document collector concept
if row[u'PARENTCONCEPTID'] == auth_doc_file_name and auth_doc_file_name != 'ARCHES RESOURCE CROSS-REFERENCE RELATIONSHIP TYPES.E32.csv':
authdoc_concept = Concept()
authdoc_concept.get(legacyoid=auth_doc_file_name.split('.')[0])
lookups.add_relationship(source=authdoc_concept.id, type='member', target=concept.id, rownum=rows.line_num)
if row[u'PARENTCONCEPTID'] == '' or (row[u'CONCEPTTYPE'].upper() != 'INDEX' and row[u'CONCEPTTYPE'].upper() != 'COLLECTOR'):
raise Exception('The row has invalid values.')
lookups.add_lookup(concept=concept, rownum=rows.line_num)
except Exception as e:
errors.append('ERROR in row %s: %s' % (rows.line_num, str(e)))
except UnicodeDecodeError as e:
errors.append('ERROR: Make sure the file is saved with UTF-8 encoding\n%s\n%s' % (str(e), traceback.format_exc()))
except Exception as e:
errors.append('ERROR: %s\n%s' % (str(e), traceback.format_exc()))
if len(errors) > 0:
errors.insert(0, 'ERRORS IN FILE: %s\n' % (filename))
errors.append('\n\n\n\n')
try:
# try and open the values file if it exists
if exists(filepath.replace('.csv', '.values.csv')):
with open(filepath.replace('.csv', '.values.csv'), 'rU') as f:
rows = unicodecsv.DictReader(f, fieldnames=['CONCEPTID','VALUE','VALUETYPE','PROVIDER'],
encoding='utf-8-sig', delimiter=',', restkey='ADDITIONAL', restval='MISSING')
rows.next() # skip header row
for row in rows:
try:
if 'ADDITIONAL' in row:
raise Exception('The row wasn\'t parsed properly. Additional fields found %s. Add quotes to values that have commas in them.' % (row['ADDITIONAL']))
else:
row_valuetype = row[u'VALUETYPE'].strip()
#.........这里部分代码省略.........