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


Python Concept.index方法代码示例

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


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

示例1: add_concepts_from_sparql_endpoint

# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import index [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()
开发者ID:cropandsave,项目名称:arches,代码行数:36,代码来源:concept.py

示例2: add_concepts_from_sparql_endpoint

# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import index [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()
开发者ID:oswalpalash,项目名称:arches,代码行数:33,代码来源:concept.py

示例3: index_concepts

# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import index [as 别名]
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'])
开发者ID:1000camels,项目名称:arches,代码行数:47,代码来源:index_database.py

示例4: forwards_func

# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import index [as 别名]
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')
开发者ID:fargeo,项目名称:arches,代码行数:47,代码来源:0005_4_0_1.py

示例5: import_reference_data

# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import index [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)
开发者ID:archesproject,项目名称:arches,代码行数:21,代码来源:importer.py

示例6: concept

# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import index [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
开发者ID:oswalpalash,项目名称:arches,代码行数:104,代码来源:concept.py

示例7: concept

# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import index [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
开发者ID:cropandsave,项目名称:arches,代码行数:104,代码来源:concept.py

示例8: forwards_func

# 需要导入模块: from arches.app.models.concept import Concept [as 别名]
# 或者: from arches.app.models.concept.Concept import index [as 别名]
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

    arches_concept = Concept().get(id='00000000-0000-0000-0000-000000000007', include=['label'])
    arches_concept.index()
开发者ID:fargeo,项目名称:arches,代码行数:8,代码来源:0010_4_1_0.py


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