2010-09-04 170 views
4

我遇到了文字邊界識別的問題。我刪除了維基百科文檔的所有標記,現在我想獲得一個實體列表(有意義的術語)。我計劃採用二元組,三元文檔並檢查它是否存在於字典(wordnet)中。有沒有更好的方法來實現這一點。文本中的文字邊界檢測

下面是示例文本。我想,以確定實體(如圖由雙引號)

Vulcans are a humanoid species in the fictional "Star Trek" universe who evolved on the planet Vulcan and are noted for their attempt to live by reason and logic with no interference from emotion They were the first extraterrestrial species officially to make first contact with Humans and later became one of the founding members of the "United Federation of Planets"

感謝 巴拉

+0

您可能想要在語義分析中考慮各種印刷慣例,而不是剝離標記。如果推斷出您已經明確引用了您想要在其他沒有標記的文本中關聯的短語,是否是正確的? – trashgod 2010-09-04 15:18:01

回答

1

我想你在談論什麼是真正的還是新興的研究,而不是一個簡單的事情的主題應用完善的算法。

我不能給你一個簡單的「做」的答案,但這裏有一些指點過我的頭頂:

  • 我想用共發現可以正常工作(不知道在哪裏的雙字母組/卦來但是您應該將WordNet查找視爲混合系統的一部分,而不是查找已命名實體的全部和最終全部,然後,首先應用一些簡單的常識標準(大寫字母順序單詞;試着將經常使用的小寫功能詞(如'of')應用於這些;由「已知標題」加上大寫單詞組成的序列;
  • 尋找統計上你不會偶然出現的單詞序列作爲實體的候選者;
  • 你可以建立動態網頁查找嗎? (您的系統會發現大寫的序列「IBM」,並查看它是否找到例如具有文本模式「IBM is ... [organization | company | ...]」的wikipedia條目
  • 看看這裏和在「信息提取」文學一般給你一些想法:http://www-nlpir.nist.gov/related_projects/muc/proceedings/muc_7_toc.html

事實是,當你在看什麼文學存在在那裏,它似乎並不像人們正在使用非常先進的,成熟的算法。所以我認爲有很多空間來看你的數據,探索並看到你能想出什麼...祝你好運!

+0

斯坦福大學NLP命名實體識別器應該是您的第一通。它將在第一次運行中爲您提供很多價值,您可以查看代碼並瞭解如何從此處改進代碼。 – 2017-08-02 11:02:25

0

如果我理解正確,你正在尋找提取s由雙引號(「)分隔的大腿。你可以使用捕獲組的正則表達式:

String text = "Vulcans are a humanoid species in the fictional \"Star Trek\"" + 
     " universe who evolved on the planet Vulcan and are noted for their " + 
     "attempt to live by reason and logic with no interference from emotion" + 
     " They were the first extraterrestrial species officially to make first" + 
     " contact with Humans and later became one of the founding members of the" + 
     " \"United Federation of Planets\""; 
    String[] entities = new String[10];     // An array to hold matched substrings 
    Pattern pattern = Pattern.compile("[\"](.*?)[\"]"); // The regex pattern to use 
    Matcher matcher = pattern.matcher(text);   // The matcher - our text - to run the regex on 
    int startFrom = text.indexOf('"');    // The index position of the first " character 
    int endAt  = text.lastIndexOf('"');   // The index position of the last " character 
    int count  = 0;        // An index for the array of matches 
    while (startFrom <= endAt) {      // startFrom will be changed to the index position of the end of the last match 
     matcher.find(startFrom);      // Run the regex find() method, starting at the first " character 
     entities[count++] = matcher.group(1);   // Add the match to the array, without its " marks 
     startFrom = matcher.end();      // Update the startFrom index position to the end of the matched region 
    } 

或寫一個「解析器」與字符串函數:

int startFrom = text.indexOf('"');        // The index-position of the first " character 
    int nextQuote = text.indexOf('"', startFrom+1);     // The index-position of the next " character 
    int count = 0;             // An index for the array of matches 
    while (startFrom > -1) {          // Keep looping as long as there is another " character (if there isn't, or if it's index is negative, the value of startFrom will be less-than-or-equal-to -1) 
     entities[count++] = text.substring(startFrom+1, nextQuote); // Retrieve the substring and add it to the array 
     startFrom = text.indexOf('"', nextQuote+1);     // Find the next " character after nextQuote 
     nextQuote = text.indexOf('"', startFrom+1);     // Find the next " character after that 
    } 

在這兩個,樣本文本是硬編碼的緣故示例和相同的變量被假定爲存在(字符串變量名爲text)。

如果你想測試entities數組的內容:

int i = 0; 
    while (i < count) { 
     System.out.println(entities[i]); 
     i++; 
    } 

我不得不提醒你,有可能是邊境/邊界情況的問題(即當「字是在開始或結束這些例子不會如果「字符的奇偶性不均勻(即如果文本中有」奇數個「字符)的奇偶性,則按預期工作。你可以使用一個簡單的奇偶校驗前手:

static int countQuoteChars(String text) { 
     int nextQuote = text.indexOf('"');    // Find the first " character 
     int count = 0;         // A counter for " characters found 
     while (nextQuote != -1) {      // While there is another " character ahead 
      count++;         // Increase the count by 1 
      nextQuote = text.indexOf('"', nextQuote+1); // Find the next " character 
     } 
     return count;         // Return the result 
    } 

    static boolean quoteCharacterParity(int numQuotes) { 
     if (numQuotes % 2 == 0) { // If the number of " characters modulo 2 is 0 
      return true;   // Return true for even 
     } 
     return false;    // Otherwise return false 
    } 

注意,如果numQuotes恰好是0這種方法仍然返回true(因爲0模任何數字都是0,所以(count % 2 == 0)true)雖然你止跌「不想與解析先走,如果沒有「字,所以你想不想找個地方檢查此條件。

希望這有助於!

+0

這很有趣......我用雙引號包圍了實體。 – Boolean 2010-09-04 14:47:06

+1

@Algorist:由於我有類似的誤解,因此澄清您關於引號使用的問題可能很有用。 – trashgod 2010-09-04 15:14:13

0

別人問過類似的問題有關how to find "interesting" words in a corpus of text。您應該閱讀答案。特別是,博羅的回答指向一篇有趣的文章,其中使用了詞的出現密度來決定它的重要性 - 使用這樣的觀察:當文本談論某事時,它通常是指相當頻繁的事情。本文很有趣,因爲該技術不需要對正在處理的文本有先驗知識(例如,您不需要針對特定​​詞典的字典)。

本文提出了兩種算法。

第一個算法根據它們測量的重要性對單個單詞(例如「Federation」或「Trek」等)進行評分。它很容易實現,我甚至可以在Python中提供一個(不是很優雅的)實現。

第二種算法更有趣,因爲它通過完全忽略空白並使用樹結構來決定如何分割名詞短語來提取名詞短語(如「星際迷航」等)。這個算法應用於達爾文關於進化的開創性文本的結果非常令人印象深刻。然而,我承認實施這個算法需要更多的思考,因爲這篇文章給出的描述相當難以理解,作者似乎有點難以追查。也就是說,我沒有花太多時間,所以你可能會有更好的運氣。