本文整理汇总了Python中arches.app.models.concept.Concept类的典型用法代码示例。如果您正苦于以下问题:Python Concept类的具体用法?Python Concept怎么用?Python Concept使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Concept类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_region_specific_preflabel_when_language_only_version_does_not_exist
def test_get_region_specific_preflabel_when_language_only_version_does_not_exist(self):
"""
Given a language only and the system only has values that with regions specified, then
the system should pick the first preflabel with the same language code
"""
concept = Concept()
concept.values = [
ConceptValue({
'type': 'prefLabel',
'category': 'label',
'value': 'test pref label en-US',
'language': 'en-US'
}),
ConceptValue({
'type': 'prefLabel',
'category': 'label',
'value': 'test pref label es',
'language': 'es-SP'
}),
ConceptValue({
'type': 'altLabel',
'category': 'label',
'value': 'test alt label en-US',
'language': 'en-US'
})
]
self.assertEqual(concept.get_preflabel(lang='en').value, 'test pref label en-US')
示例2: test_prefer_preflabel_with_just_lang_code_match_over_exact_match_with_altlabel
def test_prefer_preflabel_with_just_lang_code_match_over_exact_match_with_altlabel(self):
"""
Given a language and region, test should pick the preflabel even if that preflabel specifies a language only
and even if an altlabel exists with the exact match
"""
concept = Concept()
concept.values = [
ConceptValue({
'type': 'prefLabel',
'category': 'label',
'value': 'test pref label en',
'language': 'en'
}),
ConceptValue({
'type': 'prefLabel',
'category': 'label',
'value': 'test pref label es',
'language': 'es-SP'
}),
ConceptValue({
'type': 'altLabel',
'category': 'label',
'value': 'test alt label en-US',
'language': 'en-US'
})
]
self.assertEqual(concept.get_preflabel(lang='en-US').value, 'test pref label en')
示例3: test_get_label_no_exact_match
def test_get_label_no_exact_match(self):
"""
Given no match on language code or region, return the first prefLabel found
"""
concept = Concept()
concept.values = [
ConceptValue({
'type': 'prefLabel',
'value': 'bier',
'language': 'nl'
}),
ConceptValue({
'type': 'prefLabel',
'category': 'label',
'value': 'beer',
'language': 'es-SP'
}),
ConceptValue({
'type': 'altLabel',
'category': 'label',
'value': 'test alt label en-US',
'language': 'en-US'
})
]
pl = concept.get_preflabel('fr-BE')
self.assertEquals(pl.type,'prefLabel')
self.assertEquals(pl.value,'bier' or 'beer')
self.assertEquals(pl.language,'nl' or 'es-SP')
示例4: manage_parents
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()
示例5: make_collection
def make_collection(request, conceptid):
concept = Concept().get(id=conceptid, values=[])
try:
collection_concept = concept.make_collection()
return JSONResponse({'collection': collection_concept, 'message':{'title': _('Success'), 'text': _('Collection successfully created from the selected concept')}})
except:
return JSONResponse({'message':{'title': _('Unable to Make Collection'), 'text': _('Unable to make a collection from the selected concept.')}}, status=500)
示例6: confirm_delete
def confirm_delete(request, conceptid):
lang = request.GET.get("lang", settings.LANGUAGE_CODE)
concept = Concept().get(id=conceptid)
concepts_to_delete = [
concept.get_preflabel(lang=lang).value
for key, concept in Concept.gather_concepts_to_delete(concept, lang=lang).iteritems()
]
# return HttpResponse('<div>Showing only 50 of %s concepts</div><ul><li>%s</ul>' % (len(concepts_to_delete), '<li>'.join(concepts_to_delete[:50]) + ''))
return HttpResponse("<ul><li>%s</ul>" % ("<li>".join(concepts_to_delete) + ""))
示例7: get_evaluation_path
def get_evaluation_path(valueid):
value = models.Values.objects.get(pk=valueid)
concept_graph = Concept().get(id=value.conceptid_id, include_subconcepts=False,
include_parentconcepts=True, include_relatedconcepts=False, up_depth_limit=None, lang=lang)
paths = []
for path in concept_graph.get_paths(lang=lang)[0]:
if path['label'] != 'Arches' and path['label'] != 'Evaluation Criteria Type':
paths.append(path['label'])
return '; '.join(paths)
示例8: confirm_delete
def confirm_delete(request, conceptid):
lang = request.GET.get('lang', settings.LANGUAGE_CODE)
try:
concept = Concept().get(id=conceptid)
except Exception as es1:
return render_to_response('404.htm', {
'main_script': '404',
'active_page': '404'
},
context_instance=RequestContext(request))
concepts_to_delete = [concept.get_preflabel(lang=lang).value for key, concept in Concept.gather_concepts_to_delete(concept, lang=lang).iteritems()]
#return HttpResponse('<div>Showing only 50 of %s concepts</div><ul><li>%s</ul>' % (len(concepts_to_delete), '<li>'.join(concepts_to_delete[:50]) + ''))
return HttpResponse('<ul><li>%s</ul>' % ('<li>'.join(concepts_to_delete) + ''))
示例9: test_get_label_no_exact_match
def test_get_label_no_exact_match(self):
"""
Given no match on language code or region, return the first prefLabel found
"""
values = [
{'type': 'prefLabel', 'value': 'bier', 'language': 'nl'},
{'type': 'prefLabel', 'value': 'beer', 'language': 'en'},
]
c = Concept({'values': values})
pl = c.get_preflabel('fr-BE')
self.assertEquals(pl.type,'prefLabel')
self.assertEquals(pl.value,'bier')
self.assertEquals(pl.language,'nl')
示例10: resource_manager
def resource_manager(request, resourcetypeid='', form_id='default', resourceid=''):
if resourceid != '':
resource = Resource(resourceid)
elif resourcetypeid != '':
resource = Resource({'entitytypeid': resourcetypeid})
if form_id == 'default':
form_id = resource.form_groups[0]['forms'][0]['id']
form = resource.get_form(form_id)
if request.method == 'DELETE':
resource.delete_index()
se = SearchEngineFactory().create()
realtionships = resource.get_related_resources(return_entities=False)
for realtionship in realtionships:
se.delete(index='resource_relations', doc_type='all', id=realtionship.resourcexid)
realtionship.delete()
resource.delete()
return JSONResponse({ 'success': True })
if request.method == 'POST':
data = JSONDeserializer().deserialize(request.POST.get('formdata', {}))
form.update(data, request.FILES)
with transaction.atomic():
if resourceid != '':
resource.delete_index()
resource.save(user=request.user)
resource.index()
resourceid = resource.entityid
return redirect('resource_manager', resourcetypeid=resourcetypeid, form_id=form_id, resourceid=resourceid)
min_max_dates = models.Dates.objects.aggregate(Min('val'), Max('val'))
if request.method == 'GET':
if form != None:
lang = request.GET.get('lang', settings.LANGUAGE_CODE)
form.load(lang)
return render(request, 'resource-manager.htm', {
'form': form,
'formdata': JSONSerializer().serialize(form.data),
'form_template': 'views/forms/' + form_id + '.htm',
'form_id': form_id,
'resourcetypeid': resourcetypeid,
'resourceid': resourceid,
'main_script': 'resource-manager',
'active_page': 'ResourceManger',
'resource': resource,
'resource_name': resource.get_primary_name(),
'resource_type_name': resource.get_type_name(),
'form_groups': resource.form_groups,
'min_date': min_max_dates['val__min'].year if min_max_dates['val__min'] != None else 0,
'max_date': min_max_dates['val__max'].year if min_max_dates['val__min'] != None else 1,
'timefilterdata': JSONSerializer().serialize(Concept.get_time_filter_data()),
})
else:
return HttpResponseNotFound('<h1>Arches form not found.</h1>')
示例11: index_concepts
def index_concepts():
"""
Collects all concepts and indexes both concepts and concept_labels
"""
se = SearchEngineFactory().create()
se.delete_index(index='concept_labels')
se.delete(index='term', body='{"query":{"bool":{"must_not":[{"constant_score":{"filter":{"missing":{"field":"value.options.conceptid"}}}}],"must":[],"should":[]}}}')
Resource().prepare_term_index(create=True)
print 'indexing concepts'
start = datetime.now()
cursor = connection.cursor()
cursor.execute("""select conceptid from concepts.concepts""")
conceptids = cursor.fetchall()
for c in conceptids:
if c[0] not in CORE_CONCEPTS:
concept = Concept().get(id=c[0], include_subconcepts=True, include_parentconcepts=False, include=['label'])
concept.index()
end = datetime.now()
duration = end - start
print 'indexing concepts required', duration.seconds, 'seconds'
cursor = connection.cursor()
sql = """
select conceptid, conceptlabel from concepts.vw_concepts where conceptid not in ('%s')
""" % ("','".join(CORE_CONCEPTS))
cursor.execute(sql)
concepts = cursor.fetchall()
concept_index_results = {'count':len(concepts), 'passed':0, 'failed':0}
for conceptid, conceptvalue in concepts:
result = get_indexed_concepts(se, conceptid, conceptvalue)
if result != 'passed':
concept_index_results['failed'] += 1
else:
concept_index_results['passed'] += 1
status = 'Passed' if concept_index_results['failed'] == 0 else 'Failed'
print '\nConcept Index Results:'
print "Status: {0}, In Database: {1}, Indexed: {2}".format(status, concept_index_results['count'], concept_index_results['passed'])
示例12: forwards_func
def forwards_func(apps, schema_editor):
# We get the model from the versioned app registry;
# if we directly import it, it'll be the wrong version
extensions = [os.path.join(settings.ONTOLOGY_PATH, x) for x in settings.ONTOLOGY_EXT]
management.call_command('load_ontology', source=os.path.join(settings.ONTOLOGY_PATH, settings.ONTOLOGY_BASE),
version=settings.ONTOLOGY_BASE_VERSION, ontology_name=settings.ONTOLOGY_BASE_NAME, id=settings.ONTOLOGY_BASE_ID, extensions=','.join(extensions), verbosity=0)
Ontology = apps.get_model("models", "Ontology")
Node = apps.get_model("models", "Node")
Edge = apps.get_model("models", "Edge")
for ontology in Ontology.objects.filter(parentontology=None):
g = Graph()
g.parse(ontology.path.path)
for extension in Ontology.objects.filter(parentontology=ontology):
g.parse(extension.path.path)
ontology_classes = set()
ontology_properties = set()
for ontology_property,p,o in g.triples((None, None, RDF.Property)):
ontology_properties.add(ontology_property)
for s,p,domain_class in g.triples((ontology_property, RDFS.domain, None)):
ontology_classes.add(domain_class)
for s,p,range_class in g.triples((ontology_property, RDFS.range, None)):
ontology_classes.add(range_class)
for ontology_class,p,o in g.triples((None, None, RDFS.Class)):
ontology_classes.add(ontology_class)
for ontology_class in ontology_classes:
for node in Node.objects.filter(ontologyclass=str(ontology_class).split('/')[-1], graph__in=ontology.graphs.all()):
node.ontologyclass = ontology_class
node.save()
for ontology_property in ontology_properties:
for edge in Edge.objects.filter(ontologyproperty=str(ontology_property).split('/')[-1], graph__in=ontology.graphs.all()):
edge.ontologyproperty = ontology_property
edge.save()
# index base Arches concept
arches_concept = Concept().get(id='00000000-0000-0000-0000-000000000001', include=['label'])
arches_concept.index()
DValueType = apps.get_model("models", "DValueType")
DValueType.objects.create(valuetype='identifier', category='identifiers', namespace='dcterms', datatype='text')
示例13: home_page
def home_page(request):
lang = request.GET.get('lang', settings.LANGUAGE_CODE)
min_max_dates = models.Dates.objects.aggregate(Min('val'), Max('val'))
return render(request, 'search.htm', {
'main_script': 'search',
'active_page': 'Search',
'min_date': min_max_dates['val__min'].year if min_max_dates['val__min'] != None else 0,
'max_date': min_max_dates['val__max'].year if min_max_dates['val__min'] != None else 1,
'timefilterdata': JSONSerializer().serialize(Concept.get_time_filter_data()),
})
示例14: add_concepts_from_sparql_endpoint
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()
示例15: get_concepts
def get_concepts(self, uris):
"""
Get a list of concepts given a list of AAT uris like http://vocab.getty.edu/aat/300380087
"""
concepts = []
langs = []
for lang in self.allowed_languages:
langs.append('\"%s\"' % (lang))
for uri in uris.split(','):
query = """
SELECT ?value ?type WHERE {
{
<%s> skos:prefLabel ?value .
BIND('prefLabel' AS ?type)
}
UNION
{
<%s> skos:scopeNote [rdf:value ?value] .
BIND('scopeNote' AS ?type)
}
FILTER (lang(?value) in (%s))
}""" % (uri, uri, ','.join(langs))
results = self.perform_sparql_query(query)
if len(results["results"]["bindings"]) > 0 :
concept = Concept()
concept.nodetype = 'Concept'
for result in results["results"]["bindings"]:
concept.addvalue({
'type': result["type"]["value"],
'value': result["value"]["value"],
'language': result["value"]["xml:lang"]
})
concepts.append(concept)
else:
raise Exception(_("<strong>Error in SPARQL query:</strong><br>Test this query directly by pasting the query below into the Getty's own SPARQL endpoint at <a href='http://vocab.getty.edu/sparql' target='_blank'>http://vocab.getty.edu/sparql</a><i><pre>%s</pre></i>Query returned 0 results, please check the query for errors. You may need to add the appropriate languages into the database for this query to work<br><br>") % (query.replace('<', '<').replace('>', '>')))
return concepts