我正在使用可在此处找到的雪球词干http://snowball.tartarus.org/
我正在使用这个论坛问题为我自己的项目使用词干算法
Is there a java implementation of Porter2 stemmer
我使用给定的类并使用前面回答的帖子中给出的代码
Class stemClass = Class.forName("org.tartarus.snowball.ext." + lang + "Stemmer");
stemmer = (SnowballProgram) stemClass.newInstance();
stemmer.setCurrent("your_word");
stemmer.stem();
String your_stemmed_word = stemmer.getCurrent();
但是当我使用try catch语句时,我收到此错误
assmt1/invert3.java:339: error: incompatible types: try-with-resources not applicable to variable type
try( Class stemClass = Class.forName("org.tartarus.snowball.ext." +"english"+ "Stemmer");
^
(Class cannot be converted to AutoCloseable)
assmt1/invert3.java:340: error: incompatible types: try-with-resources not applicable to variable type
SnowballStemmer stemmer = (SnowballStemmer) stemClass.newInstance())
^
(SnowballStemmer cannot be converted to AutoCloseable)
2 errors
真的不确定如何解决这个问题
答案 0 :(得分:1)
只能在try-with-resources语句声明中使用实现Sub RunSubtotal()
Dim WS As Worksheet
Dim MaxRow As Long, I As Long
Dim Tot As Double
Dim Dte As String
Set WS = ActiveSheet
MaxRow = WS.Range("A" & WS.Rows.Count).End(xlUp).Row
Tot = 0
'---> Clear Col C
WS.Range("C:C").ClearContents
'---> Sort Worksheet by Date
WS.UsedRange.Sort key1:=WS.Range("A1"), order1:=xlAscending, Header:=xlYes
Dte = WS.Cells(1, "A")
'---> Start Process
For I = 1 To MaxRow + 1
If WS.Range("A" & I) <> Dte Then
WS.Cells(I - 1, "C") = Tot
Dte = WS.Cells(I, "A")
Tot = 0
End If
Tot = Tot + Val(WS.Cells(I, "B"))
Next I
MsgBox ("Totals inserted in Col C by date successfully.")
End Sub
的类。
AutoCloseable
语句是一个声明一个的try语句 或更多资源。 资源是必须在之后关闭的对象 程序完成了。 try-with-resources语句 确保在语句结束时关闭每个资源。任何 实现try-with-resources
的对象,包括所有 实现java.lang.AutoCloseable
的对象可以用作资源。
java.io.Closeable
和Class
不是SnowballStemmer
。将其放在try块中:
AutoCloseable