용어 x 용어 매트릭스를 계산해야하는 매우 오랜 시간 동안 문제가 발생했습니다. 그래서, 키워드 및 문장 아래은 2 개 배열이 있습니다계산 용어 x 용어 매트릭스
String[] Keywords = {"Human", "Machine", "Interface", "Application" };
String[] Sentence = {"Human is Machine", "Interface of Robot", "Application on Human"};
다음, 나는 아래 그림과 같이를 집계해야합니다.
논리 : 행과 열이 동일한 키워드의 경우
- 우리는 0을 넣어.
- 인간 (행) x 기계 (열) 공간에서이 두 문자가 동일한 문장에 한 번 나타나서 (즉, 배열의 첫 번째 문장 ) 1을 넣습니다.
- 인간 (행) x 인터페이스 (열)에서이 두 단어 인 이 문장에 함께 존재하지 않기 때문에 0을 넣습니다.
- 대/소문자를 구분하지 않습니다.
- 다음 열로 이동 한 후 다음 행으로 이동하십시오.
이것은 시도했지만 어쨌든 뭔가 잘못되었습니다.
public class Test {
public static int [][] matrix;
public static void main(String[] args) throws Exception {
String[] Keywords = {"Human", "Machine", "Interface", "Application" };
String[] Sentence = {"Human is Machine", "Interface of Robot", "Application on Human"};
int [][] matrix = new int[Keywords.length][Keywords.length]; //initialize matrix
System.out.println(Arrays.toString(Keywords));
System.out.println("\n"+ Arrays.toString(Sentence));
for (int i=0;i<Keywords.length;i++)
{
int count = 0;
for (int q=1;q<Sentence.length;q++)
{
if (Keywords[i].contains(Sentence[q]))
{
matrix[i][q] = count++;
}
}
}
System.out.println(Arrays.deepToString(matrix));
}
}
도움을 주시면 감사하겠습니다. 감사!