一个简陋的中文自动分词程序

 

程序采用最大匹配法完成。

其中采用的语料库来自于詹卫东:

http://ccl.pku.edu.cn/doubtfire/Course/Chinese%20Information%20Processing/2002_2003_1.htm

程序也参考了他的。

其中的表words结构是:wid (int), word(文本), wfreq(int)

而涉及的另外一个自定义的结构:

 

public   struct  wordsStr 
{
    
public int wid;//表示ID
    public string wordPrase;
    
public int wFreq;//词出现的次数
    public PartofWord eNumPoW;//词性

}
;

整体程序如下:

操作流程为:打开数据库,将数据库中文件读入到DataSet中。并形成一个ArrayList的字典结构。

打开要分词的文件--->分词(A:处理非中文字符 B:处理标点符号 C处理纯中文字符串)

using  System;
using  System.Drawing;
using  System.Collections;
using  System.ComponentModel;
using  System.Windows.Forms;
using  System.Data;
using  System.Data.OleDb;
using  System.IO;
using  System.Collections.Specialized;
using  System.Text;
using  wordLibrary_keqian070507;

namespace  NLP_WordSeg
{
    
    
/// <summary>
    
/// Form1 的摘要说明。
    
/// </summary>

    public class Form1 : System.Windows.Forms.Form
    
{
        
private System.Windows.Forms.Button button1;

        
///<summary>
        
///变量,用来链接数据库使用,DataConnect,and so on
        
///<summary>

        private System.Data.OleDb.OleDbConnection _connOle;
        
private System.Data.DataSet _dataSet;
        
private string _fileNameStr;
        
private bool _openDBb;
        
private char[] _separatorsC = { '','',''};
        
private const string _strExt = "_seg";
        
private const string _Separator = @"";
        
private const int _iNumberMax = 4;

        
private  ArrayList[] LibArray = new ArrayList[0x9FA5-0x4E00+1];//用来记录数据


        
private System.Windows.Forms.Button btOpenFile;
        
private System.Windows.Forms.GroupBox groupBox1;
        
private System.Windows.Forms.GroupBox groupBox2;
        
private System.Windows.Forms.Button btMMMethod;
        
private System.Windows.Forms.TextBox textBox1;
        
private System.Windows.Forms.Label label1;

        
/// <summary>
        
/// 必需的设计器变量。
        
/// </summary>

        private System.ComponentModel.Container components = null;

        
public Form1()
        
{
            
//
            
// Windows 窗体设计器支持所必需的
            
//
            InitializeComponent();

            
//
            
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
            
//

            _connOle 
= null;
            _dataSet 
= new DataSet();
            _fileNameStr 
= "";
            _openDBb 
= false;

            
for (int i = 0; i< 0x9FA5-0x4E00+1; i++)
            
{
                LibArray[i] 
= new ArrayList();
            }

        }


        
/// <summary>
        
/// 清理所有正在使用的资源。
        
/// </summary>

        protected override void Dispose( bool disposing )
        
{
            
if( disposing )
            
{
                
if (components != null
                
{
                    components.Dispose();
                }

            }

            
base.Dispose( disposing );
        }



        
Windows 窗体设计器生成的代码
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
坦克大战是一个经典的游戏,下面我来写一个基于Python的简单版坦克大战游戏代码。这个游戏是基于Pygame库实现的,需要先安装Pygame库。 ```python import pygame import random # 初始化Pygame pygame.init() # 定义游戏界面大小 screen_width = 640 screen_height = 480 # 创建游戏界面 screen = pygame.display.set_mode((screen_width, screen_height)) # 设置游戏界面标题 pygame.display.set_caption('坦克大战') # 加载坦克和子弹图片 tank_image = pygame.image.load('tank.png') bullet_image = pygame.image.load('bullet.png') # 定义坦克类 class Tank: def __init__(self, x, y): self.x = x self.y = y self.speed = 5 self.direction = random.choice(['up', 'down', 'left', 'right']) self.image = tank_image self.rect = self.image.get_rect() self.rect.x = self.x self.rect.y = self.y def move(self): if self.direction == 'up': self.y -= self.speed elif self.direction == 'down': self.y += self.speed elif self.direction == 'left': self.x -= self.speed elif self.direction == 'right': self.x += self.speed # 边界检测 if self.x < 0: self.x = 0 elif self.x > screen_width - self.rect.width: self.x = screen_width - self.rect.width if self.y < 0: self.y = 0 elif self.y > screen_height - self.rect.height: self.y = screen_height - self.rect.height self.rect.x = self.x self.rect.y = self.y def fire(self): return Bullet(self.x, self.y, self.direction) # 定义子弹类 class Bullet: def __init__(self, x, y, direction): self.x = x self.y = y self.speed = 10 self.direction = direction self.image = bullet_image self.rect = self.image.get_rect() self.rect.x = self.x self.rect.y = self.y def move(self): if self.direction == 'up': self.y -= self.speed elif self.direction == 'down': self.y += self.speed elif self.direction == 'left': self.x -= self.speed elif self.direction == 'right': self.x += self.speed # 边界检测 if self.x < 0 or self.x > screen_width or self.y < 0 or self.y > screen_height: return False self.rect.x = self.x self.rect.y = self.y return True # 创建坦克和子弹 player_tank = Tank(100, 100) enemy_tank = Tank(400, 300) bullets = [] # 游戏主循环 running = True while running: # 处理事件 for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: bullets.append(player_tank.fire()) # 移动坦克和子弹 player_tank.move() enemy_tank.move() for bullet in bullets: if not bullet.move(): bullets.remove(bullet) # 绘制游戏界面 screen.fill((255, 255, 255)) screen.blit(player_tank.image, player_tank.rect) screen.blit(enemy_tank.image, enemy_tank.rect) for bullet in bullets: screen.blit(bullet.image, bullet.rect) pygame.display.update() # 退出Pygame pygame.quit() ``` 在这个游戏中,我们定义了两个类:`Tank`表示坦克,`Bullet`表示子弹。在游戏主循环中,我们不断处理事件、移动坦克和子弹、绘制游戏界面。玩家可以按空格键发射子弹。这个游戏还很简陋,你可以根据自己的需要进行扩展和完善,例如添加音效、敌方坦克、障碍物等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值