Example #1
0
def getIdUri():
    onto = ontology.Ontology()
    if request.method == 'POST':
        conceptid = request.form['id']
        index = request.form['indexes']
        if conceptid and index:
            if index != '0':
                results = onto.getConceptById(conceptid, indexValue=index)
                finalResult = resultProcessin(results)
                tmp1 = []
                mylist = []
                if not isinstance(finalResult, bool):
                    for concept in finalResult:
                        if str(concept.get('id')) == str(conceptid) and len(
                                str(concept.get('id'))) == len(str(conceptid)):
                            tmp1.append(concept)
                            break
                        elif concept.get('id') not in mylist:
                            mylist.append(concept.get('id'))
                    del mylist
                    if len(tmp1) > 0 and tmp1:
                        return render_template('user_result.html',
                                               buckets=onto.buckets,
                                               finalResult=tmp1)
                    elif not tmp1 or len(tmp1) == 0:
                        message = 'No result available'
                        return render_template('user_stat.html',
                                               message=message)
                else:
                    message = 'No result for query ' + conceptid
                    return render_template('user_stat.html',
                                           message=message,
                                           buckets=onto.buckets)
            else:
                results = onto.getConceptById(conceptid, indexValue=None)
                finalResult = resultProcessin(results)
                tmp1 = []
                mylist = []
                if not isinstance(finalResult, bool):
                    for concept in finalResult:
                        if concept.get('id') not in mylist and concept.get(
                                'id') != conceptid:
                            mylist.append(concept.get('id'))
                        elif concept.get('id') not in mylist:
                            tmp1.append(concept)
                            break
                    del mylist
                    return render_template('user_result.html',
                                           buckets=onto.buckets,
                                           finalResult=tmp1)
                else:
                    message = 'No result for query ' + conceptid
                    return render_template('user_stat.html',
                                           message=message,
                                           buckets=onto.buckets)
    else:
        message = 'Request should be POST'
        return render_template('user_stat.html',
                               message=message,
                               buckets=onto.buckets)
Example #2
0
def getIndexes():
    onto = ontology.Ontology()
    if onto.buckets:

        return render_template('user_indexes.html', buckets=onto.buckets)
    else:
        message = 'Problem on your request'
        return render_template('index.html', message=message)
Example #3
0
def home():
    onto = ontology.Ontology()
    buckets = onto.buckets
    print(buckets)
    types = onto.types
    print(types)

    return render_template('user_stat.html', buckets=buckets)
Example #4
0
def ontologies():
    onto = ontology.Ontology()
    allindex = onto.noIndexQuery()
    if allindex:
        print(onto.buckets)
        return jsonify({"ontologies": onto.buckets})
    else:
        message = 'Problem on your request'
        return jsonify({'message': message})
Example #5
0
def getontologies():
    onto = ontology.Ontology()
    allindex = onto.noIndexQuery()
    if allindex:
        aggregations = allindex['aggregations']
        typeAgg = aggregations['typesAgg']
        buckets = typeAgg['buckets']
        return buckets
    else:
        message = 'Problem on your request'
        return message
Example #6
0
def saveOntology():
    onto = ontology.Ontology()
    buckets = onto.buckets
    if request.method == 'POST':
        if 'ontologyFile' not in request.files:
            message = 'No file to upload'
            return render_template('admin_stat.html',
                                   message=message,
                                   buckets=buckets)
        else:
            file = request.files['ontologyFile']
            if file.filename == '':
                message = 'No selected file'
                return render_template('admin_stat.html',
                                       message=message,
                                       buckets=buckets)
            else:
                if file and allowed_file(file.filename):
                    onto = ontology.Ontology()
                    filename = secure_filename(file.filename)
                    print(filename)
                    file.save(
                        os.path.join(app.config['UPLOAD_FOLDER'], filename))
                    index = request.form['index']
                    type = request.form['type']
                    if onto.storeOntology(UPLOAD_FOLDER + '/' + filename, type,
                                          index):
                        message = 'Ontology saved successfully'
                        return redirect(
                            url_for('administrator',
                                    message=message,
                                    buckets=onto.buckets))

                    else:
                        message = 'Something went wrong while save ontology in database'
                        return render_template('admin_stat.html',
                                               message=message,
                                               buckets=buckets)
    else:
        return redirect(url_for('administrator', buckets=buckets))
Example #7
0
def manualAnnotation():
    print('annotatin')
    onto = ontology.Ontology()
    if request.method == 'POST':
        print('annotatin1')
        if request.form['uri'] and request.form['value']:
            print('annotatin2')
            uriValue = request.form['uri']
            valueObj = request.form['value']
            uri = URIRef(uriValue)
            g = Graph()
            g.parse(uri)
            print('annotation3')
            listResult = []
            listProperty = []
            for subj, pred, obj in g:
                print(subj)
                if subj == uri and valueObj in obj:
                    print(subj, '---', pred, '---', obj)
                    listResult.append({
                        'uri': subj,
                        'predicate': pred,
                        'object': obj
                    })
                    uriPred = URIRef(pred)
                    gPred = Graph()
                    gPred.parse(uriPred)
                    for objPred in gPred.objects(subject=uriPred,
                                                 predicate=RDF.type):
                        print('---Type', objPred)
                        listProperty.append(objPred)
            if len(listResult) > 0:
                print('annotatin4')
                return render_template('user_result_annotation.html',
                                       buckets=onto.buckets,
                                       words=valueObj,
                                       finalResult=listResult)
            elif request.form[
                    'indexes'] == '0' and not request.form['newontology']:
                print('annotatin5')
                words = request.form['value']
                procewords = textProcessing(words)
                results = onto.queryOntology(procewords)
                if results is None:
                    exit()
                else:
                    finalResult = resultProcessin(results)
                    tmp1 = []
                    mylist = []
                    for concept in finalResult:
                        if concept.get('subject') not in mylist:
                            conceptLabel = concept.get('label')
                            words = str(" ".join(words))
                            concept.update({
                                'similarity':
                                float(
                                    distance.get_jaro_distance(conceptLabel,
                                                               str(words),
                                                               winkler=True,
                                                               scaling=0.1))
                            })
                            print(concept)
                            tmp1.append(concept)
                            mylist.append(concept.get('subject'))
                    del mylist
                    tmp1 = sorted(tmp1,
                                  key=lambda k: k['similarity'],
                                  reverse=True)
                    print('annotation5')
                    return render_template('user_result_annotation.html',
                                           buckets=onto.buckets,
                                           words=words,
                                           uri=uriValue,
                                           yourresult=tmp1)
    else:
        message = 'No data entered'
        return render_template('user_stat.html',
                               buckets=onto.buckets,
                               message=message)
Example #8
0
def getMatchFromDatabaseOrLink():
    onto = ontology.Ontology()
    print(' route : /match ')
    if request.method == 'POST':
        words = request.form['words']
        print('user words :' + words)
        procewords = textProcessing(words)
        print('process word from user : '******'indexes'] == '0' and not request.form['newontology']:
            print(
                'condition request.form[indexes] == 0 and not request.form[newontology]'
            )
            results = onto.queryOntology(procewords)
            finalResult = resultProcessin(results)
            tmp1 = []
            mylist = []
            for concept in finalResult:
                if concept.get('subject') not in mylist:
                    conceptLabel = concept.get('label')
                    words = str(" ".join(procewords))
                    newLabel = textProcessing(conceptLabel)
                    joinNewLable = str(" ".join(newLabel))
                    concept.update({
                        'similarity':
                        float(
                            distance.get_jaro_distance(joinNewLable,
                                                       str(words),
                                                       winkler=True,
                                                       scaling=0.1))
                    })
                    tmp1.append(concept)
                    mylist.append(concept.get('subject'))
            del mylist
            tmp1 = sorted(tmp1, key=lambda k: k['similarity'], reverse=True)
            return render_template('user_result.html',
                                   buckets=onto.buckets,
                                   words=words,
                                   finalResult=tmp1)
        elif request.form['indexes'] == '0' and request.form['newontology']:
            print(
                'condition request.form[indexes] == 0 and request.form[newontology]'
            )
            newOnto = request.form['newontology']
            print('new ontology' + newOnto)
            results = onto.queryOntology(procewords)
            finalResult = resultProcessin(results)
            yourresult = onto.personalOntology(procewords, newOnto)
            print('result from online ontology')
            print(yourresult)
            print(
                '-----------------------------------------------------------------------------------------------'
            )
            tmp1 = []
            mylist = []
            for concept in finalResult:
                if concept.get('subject') not in mylist:
                    conceptLabel = concept.get('label')
                    words = str(" ".join(procewords))
                    newLabel = textProcessing(conceptLabel)
                    joinNewLable = str(" ".join(newLabel))
                    concept.update({
                        'similarity':
                        float(
                            distance.get_jaro_distance(joinNewLable,
                                                       str(words),
                                                       winkler=True,
                                                       scaling=0.1))
                    })
                    print(concept)
                    tmp1.append(concept)
                    mylist.append(concept.get('subject'))
            del mylist
            tmp1 = sorted(tmp1, key=lambda k: k['similarity'], reverse=True)
            print(tmp1)
            tmp2 = []
            mylist = []
            for concept in yourresult:
                if concept.get('subject') not in mylist:
                    tmp2.append(concept)
                    mylist.append(concept.get('subject'))
            tmp2 = sorted(tmp2, key=lambda k: k['similarity'], reverse=True)
            print(tmp2)
            tmp = []
            for concept in tmp1:
                tmp.append(concept)

            for concept in tmp2:
                tmp.append(concept)

            tmp = sorted(tmp, key=lambda k: k['similarity'], reverse=True)
            print('-------------------------- tmp ---------------------------')
            print(tmp)
            return render_template('user_result.html',
                                   buckets=onto.buckets,
                                   words=words,
                                   finalResult=tmp1,
                                   yourresult=tmp2,
                                   combine=tmp)
        elif request.form['indexes'] != '0' and not request.form['newontology']:
            print('ontology selected &&  no other ontology')
            index = request.form['indexes']
            print(index)
            print('words')
            print(procewords)
            results = onto.queryOntology(procewords,
                                         typeValue=None,
                                         indexValue=index)
            finalResult = resultProcessin(results)
            tmp1 = []
            mylist = []
            for concept in finalResult:
                if concept.get('subject') not in mylist:
                    conceptLabel = concept.get('label')
                    words = str(" ".join(procewords))
                    newLabel = textProcessing(conceptLabel)
                    joinNewLable = str(" ".join(newLabel))
                    concept.update({
                        'similarity':
                        float(
                            distance.get_jaro_distance(joinNewLable,
                                                       str(words),
                                                       winkler=True,
                                                       scaling=0.1))
                    })
                    print(concept)
                    tmp1.append(concept)
                    mylist.append(concept.get('subject'))
            del mylist
            tmp1 = sorted(tmp1, key=lambda k: k['similarity'], reverse=True)
            print(tmp1)

            return render_template('user_result.html',
                                   buckets=onto.buckets,
                                   types=onto.types,
                                   words=words,
                                   finalResult=tmp1)
        elif request.form['indexes'] != '0' and request.form['newontology']:
            index = request.form['indexes']
            newOnto = request.form['newontology']
            yourresult = onto.personalOntology(procewords, newOnto)
            tmp2 = []
            mylist = []
            for concept in yourresult:
                if concept.get('subject') not in mylist:
                    tmp2.append(concept)
                    mylist.append(concept.get('subject'))
            tmp2 = sorted(tmp2, key=lambda k: k['similarity'], reverse=True)

            results = onto.queryOntology(procewords,
                                         typeValue=None,
                                         indexValue=index)
            finalResult = resultProcessin(results)
            tmp1 = []
            mylist = []
            for concept in finalResult:
                if concept.get('subject') not in mylist:
                    conceptLabel = concept.get('label')
                    words = str(" ".join(procewords))
                    newLabel = textProcessing(conceptLabel)
                    joinNewLable = str(" ".join(newLabel))
                    concept.update({
                        'similarity':
                        float(
                            distance.get_jaro_distance(joinNewLable,
                                                       str(words),
                                                       winkler=True,
                                                       scaling=0.1))
                    })
                    print(concept)
                    tmp1.append(concept)
                    mylist.append(concept.get('subject'))
            del mylist
            tmp1 = sorted(tmp1, key=lambda k: k['similarity'], reverse=True)
            tmp = []
            for concept in tmp1:
                tmp.append(concept)

            for concept in tmp2:
                tmp.append(concept)

            tmp = sorted(tmp, key=lambda k: k['similarity'], reverse=True)
            return render_template('user_result.html',
                                   buckets=onto.buckets,
                                   words=words,
                                   finalResult=tmp1,
                                   yourresult=tmp2,
                                   combine=tmp)
    else:
        return render_template('user_stat.html', buckets=onto.buckets)
Example #9
0
def admin():
    onto = ontology.Ontology()
    buckets = onto.buckets
    return render_template('admin_stat.html', buckets=buckets)
Example #10
0
def getFixedSizeOfDocumentFromBegining(indexName, begin, size):
    onto = ontology.Ontology()
    result = onto.getAllConceptsOfOntology(indexName, begin=begin, size=size)
    print(result)
    return jsonify({'ontology': result})
Example #11
0
def getAllDocumentOfIndex(indexName):
    onto = ontology.Ontology()
    result = onto.getAllConceptsOfOntology(indexName)
    print(result)
    return jsonify({'ontology': result})
Example #12
0
def getDocumentByIndexAndId(indexName, id):
    onto = ontology.Ontology()
    result = onto.getDocumentById(indexName, id)
    return jsonify({'document': result})
Example #13
0
def manualAnnotation():
    print('annotatin')
    onto = ontology.Ontology()
    if request.method == 'POST':
        print('annotatin1')
        if request.form['uri'] and request.form['value']:
            print('annotatin2')
            uriValue = request.form['uri']
            valueObj = request.form['value']
            uri = URIRef(uriValue)
            g = Graph()
            g.parse(uriValue)
            print('annotation3')
            listResult = []
            for statement in g.predicate_objects():
                print(valueObj.isnumeric())
                if not valueObj.isnumeric():
                    valueObj = valueObj.strip('0')
                print(valueObj.lower())
                print(statement[1].lower())
                if valueObj.lower() in statement[1].lower():
                    listResult.append({
                        'uri': uriValue,
                        'predicate': str(statement[0]),
                        'object': str(statement[1])
                    })
            print(listResult)
            if len(listResult) > 0:
                print('annotatin4')
                return render_template('user_result_annotation.html',
                                       buckets=onto.buckets,
                                       words=valueObj,
                                       finalResult=listResult)
            elif request.form[
                    'indexes'] == '0' and not request.form['newontology']:
                print('annotatin5')
                words = request.form['value']
                procewords = textProcessing(words)
                results = onto.queryOntology(procewords)
                if results is None:
                    message = 'No result in knowlodge system and all stored ontologies'
                    return render_template('user_stat.html',
                                           buckets=onto.buckets,
                                           message=message)
                else:
                    finalResult = resultProcessin(results)
                    if not isinstance(finalResult,
                                      bool) and len(finalResult) > 0:
                        tmp1 = []
                        mylist = []
                        for concept in finalResult:
                            if concept.get('subject') not in mylist:
                                conceptLabel = concept.get('label')
                                words = str(" ".join(words))
                                concept.update({
                                    'similarity':
                                    float(
                                        distance.get_jaro_distance(
                                            conceptLabel,
                                            str(words),
                                            winkler=True,
                                            scaling=0.1))
                                })
                                print(concept)
                                tmp1.append(concept)
                                mylist.append(concept.get('subject'))
                        del mylist
                        tmp1 = sorted(tmp1,
                                      key=lambda k: k['similarity'],
                                      reverse=True)
                        print('annotation5')
                        return render_template('user_result_annotation.html',
                                               buckets=onto.buckets,
                                               words=words,
                                               uri=uriValue,
                                               yourresult=tmp1)
                    else:
                        message = 'No result available'
                        return render_template('user_stat.html',
                                               buckets=onto.buckets,
                                               message=message)
    else:
        message = 'No data entered'
        return render_template('user_stat.html',
                               buckets=onto.buckets,
                               message=message)