Ejemplo n.º 1
0
def ER_post2(request):
    """
    sdf
    :param request:
    :return:
    """
    global parse_util
    ctx = {}
    if request.POST:
        org_text = request.POST['user_text']
        text = ""
        if parse_util is None:
            parse_util = ParseUtil.Parse_Util()
        words, postags, netags, arcs = parse_util.parse_sentence(org_text)
        NE_List = get_NE_List(words, netags)
        for pair in NE_List:  # 根据实体列表,显示各个实体
            if pair[1] == 'O':
                text += pair[0]
                continue
            if temporaryok(pair[1]):
                text += "<a href='#'  data-original-title='" + get_explain(
                    pair[1]
                ) + "(暂无资料)'  data-placement='top' data-trigger='hover' data-content='" + get_detail_explain(
                    pair[1]) + "' class='popovers'>" + pair[0] + "</a>"
                continue

            text += "<a href='detail.html?title=" + pair[
                0] + "'  data-original-title='" + get_explain(
                    pair[1]
                ) + "'  data-placement='top' data-trigger='hover' data-content='" + get_detail_explain(
                    pair[1]) + "' class='popovers'>" + pair[0] + "</a>"
        ctx['rlt'] = text
    seg_word = ""
    for index in range(len(words)):  # 测试打印词性序列
        seg_word += words[index] + " <strong><small>[" + postags[
            index] + "]</small></strong> "
    seg_word += ""
    ctx['seg_word'] = seg_word
    return render(request, "index.html", ctx)
def showdetail(request):
	ctx = {}
	if 'title' in request.GET:
		# 连接数据库
		db = neo_con
		
		title = request.GET['title']
		answer = db.matchHudongItembyTitle(title)
		if answer == None:
			return render(request, "404.html", ctx) 
			
		ctx['detail'] = answer['detail']
		ctx['title'] = answer['title']
		image = answer['image']
		
		ctx['image'] = '<img src="' + str(image) + '" alt="该条目无图片" height="100%" width="100%" >'
		
		ctx['baseInfoKeyList'] = []
		List = answer['baseInfoKeyList'].split('##')
		for p in List:
			ctx['baseInfoKeyList'].append(p)
			
		ctx['baseInfoValueList'] = []
		List = answer['baseInfoValueList'].split('##')
		for p in List:
			ctx['baseInfoValueList'].append(p)
			
		text = ""
		List = answer['openTypeList'].split('##')
		for p in List:
			text += '<span class="badge bg-important">' + str(p) + '</span> '
		ctx['openTypeList'] = text
		
		text = '<table class="table table-striped table-advance table-hover"> <tbody>'
		keyList = answer['baseInfoKeyList'].split('##')
		valueList = answer['baseInfoValueList'].split('##')
		i = 0
		while i < len(keyList) :
			value = " "
			if i < len(valueList):
				value = valueList[i]
			text += "<tr>"
			text += '<td><strong>' + keyList[i] + '</strong></td>'
			text += '<td>' + value + '</td>'
			i += 1
			
			if i < len(valueList):
				value = valueList[i]
			if i < len(keyList) :
				text += '<td><strong>' + keyList[i] + '</strong></td>'
				text += '<td>' + value + '</td>'
			else :
				text += '<td><strong>' + '</strong></td>'
				text += '<td>' + '</td>'
			i += 1
			text += "</tr>"
		text += " </tbody> </table>"
		if answer['baseInfoKeyList'].strip() == '':
			text = ''
		ctx['baseInfoTable'] = text 
		
		tagcloud = ""
		taglist = wv_model.get_simi_top(answer['title'], 10)
		for tag in taglist:
			tagcloud += '<a href= "./detail.html?title=' + str(tag) + '"> '
			tagcloud += str(tag) + "</a>"
#			print(tag)
		ctx['tagcloud'] = tagcloud
		
		agri_type = ""
		ansList = tree.get_path(answer['title'], True)
		for List in ansList:
			agri_type += '<p >'
			flag = 1
			for p in List:
				if flag == 1:
					flag = 0
				else:
					agri_type += ' / '
				agri_type += str(p)
				
			agri_type += '</p>'	
		if len(ansList) == 0:
			agri_type = '<p > 暂无农业类型</p>'
		ctx['agri_type'] = agri_type	
		
		entity_type = ""
		explain = get_explain(predict_labels[answer['title']])
		detail_explain = get_detail_explain(predict_labels[answer['title']])
		entity_type += '<p > [' + explain + "]: "
		entity_type += detail_explain + "</p>"
		ctx['entity_type'] = entity_type	
			
	else:
		return render(request, "404.html", ctx) 		
			
	return render(request, "detail.html", ctx)
	
#	
## -*- coding: utf-8 -*-
#from django.http import HttpResponse
#from django.shortcuts import render_to_response
#import thulac
# 
#import sys
#sys.path.append("..")
#from neo4jModel.models import Neo4j
#
#def search_detail(request):
#	return render_to_response('detail.html')
#
## 接收GET请求数据
#def showdetail(request):
#	request.encoding = 'utf-8'
#	if 'title' in request.GET:
#		# 连接数据库
#		db = Neo4j()
#		db.connectDB()
#		title = request.GET['title']
#		answer = db.matchItembyTitle(title)
#		message = answer['detail']
#				
#	return HttpResponse(message)
Ejemplo n.º 3
0
def ER_post(request):
	ctx ={}
	if request.POST:
		key = request.POST['user_text']
		thu1 = pre_load_thu  #提前加载好了
		# 使用thulac进行分词 TagList[i][0]代表第i个词
		# TagList[i][1]代表第i个词的词性
		key = key.strip()
		TagList = thu1.cut(key, text=False)
		text = ""
		NE_List = get_NE(key)  #获取实体列表
		
		for pair in NE_List:   #根据实体列表,显示各个实体
			if pair[1] == 0:
				text += pair[0]
				continue
			if temporaryok(pair[1]):
				text += "<a href='#'  data-original-title='" + get_explain(pair[1]) + "(暂无资料)'  data-placement='top' data-trigger='hover' data-content='"+get_detail_explain(pair[1])+"' class='popovers'>" + pair[0] + "</a>"
				continue
			
			text += "<a href='detail.html?title=" + pair[0] + "'  data-original-title='" + get_explain(pair[1]) + "'  data-placement='top' data-trigger='hover' data-content='"+get_detail_explain(pair[1])+"' class='popovers'>" + pair[0] + "</a>"
		
		ctx['rlt'] = text

				
		seg_word = ""
		length = len(TagList)
		for t in TagList:   #测试打印词性序列
			seg_word += t[0]+" <strong><small>["+t[1]+"]</small></strong> "
		seg_word += ""
		ctx['seg_word'] = seg_word
		
		
		
		
	return render(request, "index.html", ctx)
Ejemplo n.º 4
0
def ER_post(request):
    ctx = {}
    if request.POST:
        key = request.POST['user_text']
        thu1 = pre_load_thu  # 提前加载好了
        # 使用thulac进行分词 TagList[i][0]代表第i个词
        # TagList[i][1]代表第i个词的词性
        key = key.strip()
        TagList = thu1.cut(key, text=False)
        text = ""
        NE_List = get_NE(key)  # 获取实体列表

        for pair in NE_List:  # 根据实体列表,显示各个实体
            if pair[1] == 0:
                text += pair[0]
                continue
            if temporaryok(pair[1]):
                text += "<a href='#'  data-original-title='" + get_explain(
                    pair[1]
                ) + "(暂无资料)'  data-placement='top' data-trigger='hover' data-content='" + get_detail_explain(
                    pair[1]) + "' class='popovers'>" + pair[0] + "</a>"
                continue

            text += "<a href='detail.html?title=" + pair[
                0] + "'  data-original-title='" + get_explain(
                    pair[1]
                ) + "'  data-placement='top' data-trigger='hover' data-content='" + get_detail_explain(
                    pair[1]) + "' class='popovers'>" + pair[0] + "</a>"

        ctx['rlt'] = text

        #		while i < length:
        #			# 尝试将2个词组合,若不是NE则组合一个,还不是就直接打印文本
        #			p1 = TagList[i][0]
        #			p2 = "*-"  # 保证p2没被赋值时,p1+p2必不存在
        #			if i+1 < length:
        #				p2 = TagList[i+1][0]
        #
        #			t1 = TagList[i][1]
        #			t2 = "*-"
        #			if i+1 < length:
        #				t2 = TagList[i+1][1]
        #
        #			p = p1 + p2
        #			if i+1 < length and preok(t1) and nowok(t2):
        #				answer = db.matchHudongItembyTitle(p)
        #				if answer != None:
        #					text += "<a href='detail.html?title=" + str(p) + "' data-toggle='tooltip' title='" + get_explain(t2) + "'>" + p + "</a>"
        #					i += 2
        #					continue
        #
        #			p = p1
        #			if nowok(t1):
        #				answer = db.matchHudongItembyTitle(p)
        #				if answer != None:
        #					text += "<a href='detail.html?title=" + str(p) + "' data-toggle='tooltip' title='" + get_explain(t1) + "'>" + p + "</a>"
        #					i += 1
        #					continue
        #				elif temporaryok(t1):
        #					text += "<a href='#' data-toggle='tooltip' title='" + get_explain(t1) + "(暂无资料)'>" + p + "</a>"
        #					i += 1
        #					continue
        #
        #
        #			i += 1
        #			text += str(p)

        seg_word = ""
        length = len(TagList)
        for t in TagList:  # 测试打印词性序列
            seg_word += t[0] + " <strong><small>[" + t[
                1] + "]</small></strong> "
        seg_word += ""
        ctx['seg_word'] = seg_word

    return render(request, "index.html", ctx)
def ER_post(request):
	ctx ={}
	if request.POST:
		key = request.POST['user_text']
		thu1 = pre_load_thu  #提前加载好了
		# 使用thulac进行分词 TagList[i][0]代表第i个词
		# TagList[i][1]代表第i个词的词性
		key = key.strip()
		TagList = thu1.cut(key, text=False)
		text = ""
		NE_List = get_NE(key)  #获取实体列表
		
		for pair in NE_List:   #根据实体列表,显示各个实体
			if pair[1] == 0:
				text += pair[0]
				continue
			if temporaryok(pair[1]):
				text += "<a href='#'  data-original-title='" + get_explain(pair[1]) + "(暂无资料)'  data-placement='top' data-trigger='hover' data-content='"+get_detail_explain(pair[1])+"' class='popovers'>" + pair[0] + "</a>"
				continue
			
			text += "<a href='detail.html?title=" + pair[0] + "'  data-original-title='" + get_explain(pair[1]) + "'  data-placement='top' data-trigger='hover' data-content='"+get_detail_explain(pair[1])+"' class='popovers'>" + pair[0] + "</a>"
		
		ctx['rlt'] = text
			
#		while i < length:
#			# 尝试将2个词组合,若不是NE则组合一个,还不是就直接打印文本
#			p1 = TagList[i][0]
#			p2 = "*-"  # 保证p2没被赋值时,p1+p2必不存在
#			if i+1 < length:
#				p2 = TagList[i+1][0]
#				
#			t1 = TagList[i][1]
#			t2 = "*-"
#			if i+1 < length:
#				t2 = TagList[i+1][1]
#			
#			p = p1 + p2
#			if i+1 < length and preok(t1) and nowok(t2):
#				answer = db.matchHudongItembyTitle(p)
#				if answer != None:
#					text += "<a href='detail.html?title=" + str(p) + "' data-toggle='tooltip' title='" + get_explain(t2) + "'>" + p + "</a>"
#					i += 2
#					continue
#			
#			p = p1
#			if nowok(t1):
#				answer = db.matchHudongItembyTitle(p)
#				if answer != None:
#					text += "<a href='detail.html?title=" + str(p) + "' data-toggle='tooltip' title='" + get_explain(t1) + "'>" + p + "</a>"
#					i += 1
#					continue
#				elif temporaryok(t1):
#					text += "<a href='#' data-toggle='tooltip' title='" + get_explain(t1) + "(暂无资料)'>" + p + "</a>"
#					i += 1
#					continue
#					
#					
#			i += 1
#			text += str(p)
				
		seg_word = ""
		length = len(TagList)
		for t in TagList:   #测试打印词性序列
			seg_word += t[0]+" <strong><small>["+t[1]+"]</small></strong> "
		seg_word += ""
		ctx['seg_word'] = seg_word
		
		
		
		
	return render(request, "index.html", ctx)