First posted PY
Import jieba import sys def stopwordslist(): stopwords = [line.strip() for line in open('D:\pythonplace\spider\weibo\stopword.txt', Encoding =' utF-4 ').readlines()] def seg_depart(sentence): Def giveres(filename, outfilename): inputs = open(filename, 'r', encoding='UTF-8') outputs = open(outfilename, 'w', Encoding =' utF-8 ') # input out.txt for line in inputs: # line = re.sub(r'^\w+\s*', '', line) # print(inputs) line_seg = seg_depart(line) # print(line_seg) if (len(line_seg) > 0): Outputs. The write (line_seg + '\ n') # print (" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - is participle and to stop words -- -- -- -- -- -- -- -- -- -- -- ") outputs. The close () inputs. The close () Print (" delete stop word and participle successfully!!" ) if __name__ == '__main__': filename = sys.argv[1] outfilename = sys.argv[2] giveres(filename, outfilename)Copy the code
Then there’s the JAVA invocation
public void jieba(String path,String filename) { String a=path+filename+".txt"; String b=path+filename+"_jieba.txt"; String[] arguments = new String[] {"python", "D:\\pythonplace\\spider\\weibo\\clean.py"}; Process process = Runtime.getRuntime().exec(arguments); int re = process.waitFor(); } catch (IOException e) { e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } return ; }Copy the code
Found that the export file has been blank online ruminating for a while found a problem in the Py IDE problem
stopwords = [line.strip() for line in open('\stopword.txt', Encoding =' utF-8 ').readlines()] This is an error and can be used directly in py because IDE automatically fills up the empty space and Java external calls to py bypass py IDE? D :\\path\ file.txtCopy the code
There are always weird problems with development