【发布时间】:2015-01-30 17:11:31
【问题描述】:
为了在 NLP 项目中使用最新的斯坦福软件包,我将 Eclipse 升级到 Java 8,如下所示:http://eclipse.org/downloads/java8/。在将合规性路径更改为 Jdk1.8 和所有其他相应更改后,我运行了该程序。
这是错误:
错误:在 edu.stanford.nlp.trees.tregex.Relation$17 类中找不到主要方法,请将主要方法定义为:
public static void main(String[] args)或 JavaFX 应用程序类必须扩展javafx.application.Application
这是程序:
import java.io.*;
import java.util.*;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;
public class Readability
{
static String line1;
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
public static void main(String args[])throws IOException
{
Readability rd=new Readability();
rd.tag(rd.count());
}
public String count()throws IOException
{
String line, line1;
System.out.println("Enter the name of the file: ");
String file=br.readLine();
StringTokenizer st = null;
StringBuilder sb=new StringBuilder();
try(FileInputStream input = new FileInputStream("E:\\"+file))
{
int data = input.read();
while(data != -1)
{
sb.append((char)data);
data = input.read();
}
}
catch(FileNotFoundException e)
{
System.err.println("File Not Found Exception : " + e.getMessage());
}
line=sb.toString();
double sentencecount=0.0000, syllablecount=0.0000;
st = new StringTokenizer(line," ,(){}[]/.;:'&?!\r\t\n\f");
StringTokenizer st1 = new StringTokenizer(line,"\r");
double wordcount=st.countTokens();
System.out.println(wordcount);
line1=line;//copy for Tagger
line+=" T";
//System.out.println(line);
char[] array = line.toCharArray();
for (int i=0;i<array.length-1;i++)
{
int turn=i+2;
if(array[i]=='?')
sentencecount++;
if((array[i]=='.')&&(((int)array[turn]>64&&(int)array[turn]<91)))
sentencecount++;
if((array[i]=='!')&&(((int)array[turn]>64&&(int)array[turn]<91)))
sentencecount++;
if((array[i]=='\'')&&(((int)array[turn]>64&&(int)array[turn]<91)))
sentencecount++;
if((array[i]=='"')&&(((int)array[turn]>64&&(int)array[turn]<91)))
sentencecount++;
}
System.out.println(sentencecount+(st1.countTokens()-1));//To include the last sentence before the 'Enter' is pressed as the ' ' follows a '.'
//System.out.println(st1.countTokens());
char[] array1=new char[st.countTokens()];
while (st.hasMoreTokens())
{
array1=st.nextToken().toCharArray();
if(array1.length>2)
{
for(int i=0;i<array1.length-1;i++)
{
char a=Character.toLowerCase(array1[i]);
char b=Character.toLowerCase(array1[i+1]);
//System.out.println(a+" "+b);
if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u')
{
if(b!='a'&&b!='e'&&b!='i'&&b!='o'&&b!='u')
{
//System.out.println("Swab");
syllablecount++;
}
}
}
char c=Character.toLowerCase(array1[array1.length-1]);
char d=Character.toLowerCase(array1[array1.length-2]);
//System.out.println(c+" "+d);
if((c=='a'||c=='i'||c=='o'||c=='u')&&(d!='a'||d!='e'||d!='i'||d!='o'||d!='u'))
{
//System.out.println("Ha!");
syllablecount++;
}
else if((c=='e')&&(d=='e'))
{
//System.out.println("Hola");
syllablecount++;
}
}
else
{
//System.out.println("Woosh");
syllablecount++;
}
}
StringTokenizer st2 = new StringTokenizer(line," ,(){}[]/.;:'&?!\r\t\n\f");//As 'The' doesn't come under the syllable count radar
while (st2.hasMoreTokens())
{
String a=st2.nextToken();
//System.out.println(a);
if(a.equalsIgnoreCase("the"))
{
syllablecount++;
}
}
System.out.println(syllablecount);
double readability=(206.835-(1.015*(wordcount/sentencecount))-(84.6*(syllablecount/wordcount)));
System.out.println("\nReadability Measure:\n\n90-100: Easily Understood by an average 11-year old.\n60-70: Easily understood by a 13-15 year old.\n0-30: Best understood by university graduates.");
if(readability>0&&readability<100)
System.out.println("The readability score, according to Flesch readability measure is: "+readability);
else
System.out.println("\nThe Readability score, according to Flesch readability measure is: "+100);
return line1;
}
public void tag(String st)
{
//System.out.println(st);
MaxentTagger tagger = new MaxentTagger("Tagger/left3words-distsim-wsj-0-18.tagger");
String tagged = tagger.tagString(st);
System.out.println(tagged);
}
}
至于代码:它寻求获得单词,句子和音节的数量。为了使用斯坦福 POS 标记器,我需要 Java 8,因为错误不受支持的主要次要版本。因此发生了变化。
【问题讨论】:
-
没有
public static void main(String[] args)方法。 Java 提供了正确的错误。 -
@LuiggiMendoza 这让我很困惑。它在第八行。
-
好吧,看起来您正在
edu.stanford.nlp.trees.tregex.Relation内部执行一个名为 17 的内部类,而不是您的Readability类。检查您是如何执行 Java 应用程序的。 -
我选择了可读性,然后运行它,我得到了这个错误:错误无法读取可读性主类。
-
首先检查类是否编译,然后确保您从正确的项目执行正确的类。
标签: java eclipse stanford-nlp