⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wordtable.java

📁 该软件实现了正向增字最大匹配和未登陆词的识别.程序用java语言编写,界面使用简单友好.
💻 JAVA
字号:
/*
 * WordTable.java
 *
 * Created on 2007年5月20日, 上午9:30
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package cnu.nlp;

import java.io.*;
import java.util.*;

/**
 *
 * @author gnehzuil
 */
public class WordTable {
    
    private static WordTable instance = new WordTable();
    
    public static WordTable getInstance() {
        return instance;
    }
    
    private Set<String> logonWord;
    private Set<String> firstName;
    private Set<String> placeName;
    private Set<String> transName;
    private Set<String> postfixFirstName;
    private Set<String> prefixFirstName;
    private Set<String> prepWord;
    private Set<String> chineseNumberWord;
    
    public boolean lookupLogonWord(String word) {
        if (logonWord.contains(word))
            return true;
        else
            return false;
    }
    
    public boolean lookupFirstName(String word) {
        if (firstName.contains(word))
            return true;
        else
            return false;
    }
    
    public boolean lookupPlaceName(String word) {
        if (placeName.contains(word))
            return true;
        else
            return false;
    }
    
    public boolean lookupTransName(String word) {
        if (transName.contains(word))
            return true;
        else
            return false;
    }
    
    public boolean lookupPostfixFirstName(final String word) {
        if (postfixFirstName.contains(word))
            return true;
        else
            return false;
    }
    
    public boolean lookupPrefixFirstName(final String word) {
        if (prefixFirstName.contains(word))
            return true;
        else
            return false;
    }
    
    public boolean lookupPrepWord(final String word) {
        if (prepWord.contains(word))
            return true;
        else
            return false;
    }
    
    public boolean lookupChineseNumberWord(final String word) {
        if (chineseNumberWord.contains(word))
            return true;
        else
            return false;
    }
    
    /** Creates a new instance of WordTable */
    private WordTable() {
        logonWord = new HashSet<String>();
        firstName = new HashSet<String>();
        placeName = new HashSet<String>();
        transName = new HashSet<String>();
        postfixFirstName = new HashSet<String>();
        prefixFirstName = new HashSet<String>();
        prepWord = new HashSet<String>();
        chineseNumberWord = new HashSet<String>();
        
        load();
    }
    
    private void load() {
        loadLogonWord();
        loadFirstName();
        loadPlaceName();
        loadTransName();
        initialPostfixFirstName();
        initialPrefixFirstName();
        initialPrepWord();
        initialChineseNumberWord();
    }

    private void loadLogonWord() {
        Scanner scanner = null;
        try {
            scanner = new Scanner(new File("./WordTable.txt"));
            while (scanner.hasNextLine()) {
                logonWord.add(scanner.nextLine());
            }
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } finally {
            if (scanner != null)
                scanner.close();
        }
    }

    private void loadFirstName() {
        Scanner scanner = null;
        try {
            scanner = new Scanner(new File("./FirstName.txt"));
            while (scanner.hasNextLine()) {
                firstName.add(scanner.nextLine());
            }
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } finally {
            if (scanner != null)
                scanner.close();
        }
    }

    private void loadPlaceName() {
        Scanner scanner = null;
        try {
            scanner = new Scanner(new File("./PlaceName.txt"));
            while (scanner.hasNextLine()) {
                placeName.add(scanner.nextLine());
            }
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } finally {
            if (scanner != null)
                scanner.close();
        }
    }

    private void loadTransName() {
        Scanner scanner = null;
        try {
            scanner = new Scanner(new File("./TransName.txt"));
            while (scanner.hasNextLine()) {
                transName.add(scanner.nextLine());
            }
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        } finally {
            if (scanner != null)
                scanner.close();
        }
    }
    
    private final String[] postfix = {
        "先生", "小姐", "老师", "同学", "师傅", "大师", "主席", "总统", 
        "首相", "总理", "委员长", "市长", "阁下", "之流", "总", "工", "老"
    };        
    
    private void initialPostfixFirstName() {
        for (String str : postfix) {
            postfixFirstName.add(str);
        }
    }
    
    private final String[] prefix = {
        "主席", "市长", "委员长", "总理", "首相", "书记", "老", "小"
    };

    private void initialPrefixFirstName() {
        for (String str : prefix) {
            prefixFirstName.add(str);
        }
    }

    private final String[] prep = {
        "在", "得", "的", "地", "是"
    };
    
    private void initialPrepWord() {
        for (String str : prep) {
            prepWord.add(str);
        }
    }

    private final String[] chineseNumber = {
        "一", "二", "三", "四", "五", "六", "七", 
        "八", "九", "十", "百", "千", "万", "亿",
        "个", "斤", "堆", "名", "件"
    };
    
    private void initialChineseNumberWord() {
        for (String str : chineseNumber) {
            chineseNumberWord.add(str);
        }
    }
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -