0

ここで何が起こっているのか知っている人はいますか?

最初のブロックは、私が一般的に期待するものを示しています。文字列の最初の文字はインデックス「0」にあり、「問題」の文字列はコメントアウトされ、まったく同じものに置き換えられますが、前に実行されることはありません。

public void finderTest(){
    String theDoc = "Hello, I want this to work, and work well! Do you think it will work, and if not, why not?";
    //String wordOne = "‭abc"; // old, pre-used string, used to hold a comma.
    String wordOne = "abc";// new, never run before with a comma
    String wordTwo = "and";
    System.out.println("Type of character at index '0' in theDoc: "+Character.getType(theDoc.charAt(0)));
    System.out.println("Character at index '0' in theDoc: "+theDoc.charAt(0));
    System.out.println();
    System.out.println("All of wordOne: "+"'"+wordOne+"'");
    System.out.println("Type of character at index '0' in wordOne: "+Character.getType(wordOne.charAt(0)));
    System.out.println("Character at index '0' in wordOne: "+wordOne.charAt(0));
    System.out.println();
    System.out.println("Type of Character at index '0' in wordTwo: "+Character.getType(wordTwo.charAt(0)));
    System.out.println("Character at index '0' in wordTwo: "+wordTwo.charAt(0));
}

出力が得られます:

/*
    Type of character at index '0' in theDoc: 1
Character at index '0' in theDoc: H

All of wordOne: 'abc'
Type of character at index '0' in wordOne: 2 // okay
Character at index '0' in wordOne: a // okay

Type of Character at index '0' in wordTwo: 2
Character at index '0' in wordTwo: a
*/

2 番目のブロックには、コメント アウトされた 'new' 文字列があり、'wordOne' の最初の文字は何もありません。null 文字や改行ではありません。その変数を使用して 'theDoc' 内のカンマを見つけていましたが、実行すると、インデックス '0' には何も保持されず、インデックス 1 にはカンマが含まれていました。文字列をコピーして貼り付けると、問題は残ります。ただし、コメントアウト/削除すると、問題が解消されます。

    public void finderTest(){
    String theDoc = "Hello, I want this to work, and work well! Do you think it will work, and if not, why not?";
    String wordOne = "‭abc"; // now running old string, used to hold comma
    //String wordOne = "abc"; 
    String wordTwo = "and";
    System.out.println("Type of character at index '0' in theDoc: "+Character.getType(theDoc.charAt(0)));
    System.out.println("Character at index '0' in theDoc: "+theDoc.charAt(0));
    System.out.println();
    System.out.println("All of wordOne: "+"'"+wordOne+"'");
    System.out.println("Type of character at index '0' in wordOne: "+Character.getType(wordOne.charAt(0)));
    System.out.println("Character at index '0' in wordOne: "+wordOne.charAt(0));
    System.out.println();
    System.out.println("Type of Character at index '0' in wordTwo: "+Character.getType(wordTwo.charAt(0)));
    System.out.println("Character at index '0' in wordTwo: "+wordTwo.charAt(0));
}

出力が得られます:

/*  
    Type of character at index '0' in theDoc: 1
    Character at index '0' in theDoc: H

    All of wordOne: '‭abc'
    Type of character at index '0' in wordOne: 16 // What does this mean?
    Character at index '0' in wordOne: ‭   // where is the a? (well, its in wordOne index '1'... but why??)

    Type of Character at index '0' in wordTwo: 2
    Character at index '0' in wordTwo: a
*/

このような問題を引き起こす Java のコンマや記号について何かありますか? 文字配列を使用して、ワークスペースをクリーンアップしてすべてを再構築しようとしましたが、これは何も変わりませんでした…一部のグラムが「、および」のようなものである場合、これは文内の「ngram」のインデックスを見つけるための大きな問題です。昨夜、ある時点で機能していましたが、突然機能しなくなりました。私はかなり混乱しています。

何か案は?

ありがとう、

アンドリュー

4

3 に答える 3

2

あなたの例をEclipseに貼り付けてみましたが、次のように言われました:

一部の文字は、「Cp1252」文字エンコードを使用してマップできません。

そして、文字列の最初の文字を指摘しました:

String wordOne = "abc";

"と の間に隠し文字 (印刷不可) があるようaです。

于 2012-02-12T19:35:21.033 に答える
1

文字タイプ 16 は、Unicode DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING (U+202B) に対応します。これは印刷できない文字です。確認のために16進値を印刷できます。

于 2012-02-12T19:35:32.140 に答える
0

文字列には、表示に問題のある文字が含まれています (「a」の前)。Unicode セットには、意味のある視覚的表現を持たない文字が多数あります。これはおそらくその 1 つです。

「16」は文字タイプです。たとえば、次のようになります。

COMBINING_SPACING_MARK, CONNECTOR_PUNCTUATION, CONTROL, CURRENCY_SYMBOL, DASH_PUNCTUATION, DECIMAL_DIGIT_NUMBER, ENCLOSING_MARK, END_PUNCTUATION, FINAL_QUOTE_PUNCTUATION, FORMAT, INITIAL_QUOTE_PUNCTUATION, LETTER_NUMBER, LINE_SEPARATOR, LOWERCASE_LETTER, MATH_SYMBOL, MODIFIER_LETTER, MODIFIER_SYMBOL, NON_SPACING_MARK, OTHER_LETTER, OTHER_NUMBER, OTHER_PUNCTUATION, OTHER_SYMBOL, PARAGRAPH_SEPARATOR, PRIVATE_USE, SPACE_SEPARATOR, START_PUNCTUATION、SURROGATE、TITLECASE_LETTER、UNASSIGNED、UPPERCASE_LETTER

Characterこれらはすべてクラスで定義されています。理論的には実装に依存するため、どれがどれであるかはわかりません。これらの値に対してチェックする必要があります。または、Character.getName人間が読める文字の説明を見つけるために使用することをお勧めします。

于 2012-02-12T19:36:25.250 に答える