import nltk text='I have a pen,and I like it' token=nltk.word_tokenize(text) 运行出现错误 10

我的Python版本是2.7,在pycharm里运行... 我的Python版本是2.7,在pycharm里运行 展开
 我来答
DoramiHe
2018-07-09 · 知道合伙人互联网行家
DoramiHe
知道合伙人互联网行家
采纳数:25336 获赞数:59530
2011年中山职业技术学院毕业,现担任毅衣公司京东小二

向TA提问 私信TA
展开全部
/// <summary> /// “更多符号”按下时触发的事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnMoreSymbol_Click(object sender, EventArgs e) { if (this.contextMenuMoreSymbolInitiated == false) { //string sInstall = ReadRegistry("SOFTWARE\\ESRI\\CoreRuntime"); //string path = System.IO.Path.Combine(sInstall, "Styles"); string sInstall = ""; string path = System.IO.Path.Combine(sInstall, "D:\\Program Files\\ArcGIS\\Engine10.0\\Styles"); //取得菜单项数量 string[] styleNames = System.IO.Directory.GetFiles(path, "*.ServerStyle"); ToolStripMenuItem[] symbolContextMenuItem = new ToolStripMenuItem[styleNames.Length + 1]; //循环添加其它符号菜单项到菜单 for (int i = 0; i < styleNames.Length; i++) { symbolContextMenuItem[i] = new ToolStripMenuItem(); symbolContextMenuItem[i].CheckOnClick = true; symbolContextMenuItem[i].Text = System.IO.Path.GetFileNameWithoutExtension(styleNames[i]); if (symbolContextMenuItem[i].Text == "ESRI") { symbolContextMenuItem[i].Checked = true; } symbolContextMenuItem[i].Name = styleNames[i]; } //添加“更多符号”菜单项到菜单最后一项 symbolContextMenuItem[styleNames.Length] = new ToolStripMenuItem(); symbolContextMenuItem[styleNames.Length].Text = "添加符号"; symbolContextMenuItem[styleNames.Length].Name = "AddMoreSymbol"; //添加所有的菜单项到菜单 this.contextMenuStrip.Items.AddRange(symbolContextMenuItem); this.contextMenuMoreSymbolInitiated = true; } //显示菜单 this.contextMenuStrip.Show(this.btnMoreSymbol.Location); }

添加contextMenuStripMoreSymbol控件的ItemClicked事件。单击某一菜单项时响应ItemClicked事件,将选中的ServerStyle文件导入到SymbologyControl中并刷新。当用户单击“添加符号”菜单项时,弹出打开文件对话框,供用户选择其它的ServerStyle文件。代码如下:
/// <summary> /// “更多符号”按钮弹出的菜单项单击事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void contextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { ToolStripMenuItem pToolStripMenuItem = (ToolStripMenuItem)e.ClickedItem; //如果单击的是“添加符号” if (pToolStripMenuItem.Name == "AddMoreSymbol") { //弹出打开文件对话框 if (this.openFileDialog.ShowDialog() == DialogResult.OK) { //导入style file到SymbologyControl this.axSymbologyControl.LoadStyleFile(this.openFileDialog.FileName); //刷新axSymbologyControl控件 this.axSymbologyControl.Refresh(); } } else//如果是其它选项 { if (pToolStripMenuItem.Checked == false) { this.axSymbologyControl.LoadStyleFile(pToolStripMenuItem.Name); this.axSymbologyControl.Refresh(); } else { this.axSymbologyControl.RemoveFile(pToolStripMenuItem.Name); this.axSymbologyControl.Refresh(); } } }
相信你已经盼这一步很久了吧,按照惯例,按下F5吧!大功造成。
这一讲给大家讲解图层标注的实现方法。图层标注实现起来并不复杂,本例仅做一个简单示范,只加载AE的样式库,标注选定的字段,旨在抛砖引玉。更高级的功能,如自定义样式和修改样式,由读者自己实现。主要思路: 加载图层字段 –> 加载文本样式 -> 设置文本样式。实现过程: 创建标注设置窗体 -> 创建图层标注的Command -> 添加Command到图层右键菜单。
添加一个Windows窗体,命名为LabelLayerFrm.cs。添加控件如下:

为LabelLayerFrm类添加两个成员变量:
public ILayer pLayer;
private IStyleGalleryItem pStyleGalleryItem;
重载一个构造函数:
public LabelLayerFrm(ILayer layer)
{
InitializeComponent();
pLayer = layer;
添加成员函数ReadRegistry,用于从注册表中读取ArcGIS的安装路径。
/// <summary> /// 读取注册表中的制定软件的路径 /// </summary> /// <param name="sKey"></param> /// <returns></returns> private string ReadRegistry(string sKey) { //Open the subkey for reading Microsoft.Win32.RegistryKey rk = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(sKey, true); if (rk == null) return ""; // Get the data from a specified item in the key. return (string)rk.GetValue("InstallDir"); }
添加LabelLayerFrm窗体的Load事件,以加载图层字段到下拉模型,加载文本样式到SymbologyControl控件。
private void LabelLayerFrm_Load(object sender, EventArgs e) { //加载图层字段 ITable pTable = pLayer as ITable; IField pField = null; for (int i = 0; i < pTable.Fields.FieldCount; i++) { pField = pTable.Fields.get_Field(i); cbbField.Items.Add(pField.AliasName); } cbbField.SelectedIndex = 0; //获得ArcGIS的安装路径 //string sInstall = ReadRegistry("SOFTWARE\\ESRI\\CoreRuntime"); //加载ESRI.ServerStyle 样式文件到SymbologyControl this.axSymbologyControl.LoadStyleFile("D:\\Program Files\\ArcGIS\\Engine10.0\\Styles\\ESRI.ServerStyle"); this.axSymbologyControl.GetStyleClass(esriSymbologyStyleClass.esriStyleClassTextSymbols).SelectItem(0);//这个地方有错误,SelectItem选择后不能调出涂层文本标注框 //this.axSymbologyControl.GetStyleClass(esriSymbologyStyleClass.esriStyleClassTextSymbols);//改成这句也不行,能调出对话框但是样式选择,后面代码就不能正确执行 //综上问题还是不能解决,楼主能力有限,姑且认为上一行的代码正确,只是为AE的bug }
添加axSymbologyControl1控件的OnItemSelected事件,以设置选定的样式。
private void axSymbologyControl1_OnItemSelected (object sender, ISymbologyControlEvents_OnItemSelectedEvent e)
{
pStyleGalleryItem = (IStyleGalleryItem)e.styleGalleryItem;
添加确定按扭的Click事件,为选定图层中的选定的字段以选定的样式标注。
private void btnOK_Click(object sender, EventArgs e)
IGeoFeatureLayer pGeoFeatureLayer = pLayer as IGeoFeatureLayer;
pGeoFeatureLayer.AnnotationProperties.Clear();//必须执行,因为里面有一个默认的
IBasicOverposterLayerProperties pBasic = new BasicOverposterLayerPropertiesClass();
ILabelEngineLayerProperties pLableEngine = new LabelEngineLayerPropertiesClass();
ITextSymbol pTextSymbol = new TextSymbolClass();
pTextSymbol = (ITextSymbol)pStyleGalleryItem.Item;
//你可以在这里修改样式的颜色和字体等属性,本文从略
//pTextSymbol.Color
//pTextSymbol.Font
string pLable = "[" + (string)cbbField .SelectedItem + "]";
pLableEngine.Expression = pLable;
pLableEngine.IsExpressionSimple = true;
pBasic.NumLabelsOption = esriBasicNumLabelsOption.esriOneLabelPerShape;
pLableEngine.BasicOverposterLayerProperties = pBasic;
pLableEngine.Symbol = pTextSymbol;
pGeoFeatureLayer.AnnotationProperties.Add(pLableEngine as IAnnotateLayerProperties);
pGeoFeatureLayer.DisplayAnnotation = true;
至此,标注设置窗体已经完成,如果你编译通不过,看看是不是忘了添加相关引用了。
创建一个新类,以ArcGIS的BaseCommand为模板,命名为LabelLayerCmd.cs。注意:在新建Base Command模板时,会弹出一个对话框让我们选择模板适用对象,这时我们要选择MapControl、PageLayoutControl,即选择第二项或者倒数第二项。添加LabelLayerCmd类的成员变量。
private ILayer pLayer = null;
IMapControl3 pMap;
修改默认构造函数如下:
public LabelLayerCmd(ILayer lyr,IMapControl3 map)
//
// TODO: Define values for the public properties
//
base.m_category = ""; //localizable text
base.m_caption = "标注"; //localizable text
base.m_message = "标注"; //localizable text
base.m_toolTip = "标注"; //localizable text
base.m_name = "标注"; //unique id, non-localizable (e.g. "MyCategory_MyCommand")
pLayer = lyr;
pMap = map;
try
//
// TODO: change bitmap name if necessary
//
string bitmapResourceName = GetType().Name + ".bmp";
base.m_bitmap = new Bitmap(GetType(), bitmapResourceName);
catch (Exception ex)
System.Diagnostics.Trace.WriteLine(ex.Message, "Invalid Bitmap");
修改OnClick函数为:
/// <summary>
/// Occurs when this command is clicked
/// </summary>
public override void OnClick()
// TODO: Add LabelLayerCmd.OnClick implementation
LabelLayerFrm labelLyrFrm = new LabelLayerFrm(pLayer);
labelLyrFrm.ShowDialog();
pMap.Refresh(esriViewDrawPhase.esriViewGraphics, null, null);
回到主窗体类,找到axTOCControl1_OnMouseDown事件响应函数,修改如下代码片断:
//弹出右键菜单
if (item == esriTOCControlItem.esriTOCControlItemMap)
m_menuMap.PopupMenu(e.x, e.y, m_tocControl.hWnd);
if (item == esriTOCControlItem.esriTOCControlItemLayer)
m_menuLayer.AddItem(new OpenAttributeTable(layer), -1, 2, true , esriCommandStyles.esriCommandStyleTextOnly);
//动态添加图层标注的Command到图层右键菜单
m_menuLayer.AddItem(new LabelLayerCmd(layer, m_mapControl), -1, 3, false, esriCommandStyles.esriCommandStyleTextOnly);
//弹出图层右键菜单
m_menuLayer.PopupMenu(e.x, e.y, m_tocControl.hWnd);
//移除菜单项
m_menuLayer.Remove(3);
m_menuLayer.Remove(2);
至此,已经完成图层文本标注,编译运行吧。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式