forked from mitsuki97/EPAD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
84 lines (83 loc) · 2.49 KB
/
Copy pathutils.py
File metadata and controls
84 lines (83 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# _*_coding: utf-8 _*_
# author :14166
# DATA : 9:04
# LAST MODIFIED BY :14166
# LAST MODIFIED BY : 9:04
import os
import tkinter.messagebox
from tkinter import *
def setCenteredDisply(window, width, height):
'''
设置窗口大小 并将串口居中显示
:param window: window object
:param width: set the width of window
:param height: set the height of window
:return:
'''
# get screen width
ww = window.winfo_screenwidth()
# get screen height
hw = window.winfo_screenheight()
x = (ww - width) / 2
y = (hw - height) / 2
window.geometry("%dx%d+%d+%d" % (width, height, x, y))
def max_Forward_Match_English(content,dic, row):
'''
首先分行、分句
:param content: 一篇文章
:param dic: 已包含的此表
:return: 返回单词及其id位置 不然无法回显
'''
dic = dic[0].strip().split()
lines = content.strip().split('\n')
words = []
index = []
for _idx, line in enumerate(lines):
chars = line.strip().split() # 一行文本以空格分离
for _i, w in enumerate(chars, 1):
if w in dic:
words.append(w)
index.append((int(row) + _idx, _i))
return words, index
def get_pre_ann(file_path):
file = open(file_path,'r',encoding='utf-8')
lines = file.readlines()
def getNum(path):
data = open(path,'r',encoding='utf-8')
lines = data.readlines()
certain_num = 0
uncertain_num = 0
for line in lines:
line = line.strip().split('\t')
if line[4]=='certain':
certain_num+=1
else:
uncertain_num+=1
return uncertain_num,certain_num
def Matrix2List(matrix):
'''
将矩阵转为二维列表
:param matrix:
:return: 二维列表
'''
list_matrix = []
for idx in range(matrix.shape[0]):
line = []
for idy in range(matrix.shape[1]):
line.append(matrix[idx][idy])
list_matrix.append(line)
return list_matrix
def Check():
if not os.path.exists('./Multi_Annotator'):
os.mkdir('./Multi_Annotator')
dirs = os.listdir('./Multi_Annotator')
for i in dirs:
if os.path.isfile('./Multi_Annotator/'+i):
tkinter.messagebox.showerror('错误','“Multi_Annotator”包含非法文件')
return dirs
if __name__=='__main__':
str = 'i am here, hello i am here hello \n imd fjdkf am hello'
word = ['hello']
words,index = max_Forward_Match_English(str,word, 2)
print(words)
print(index)