首页 文章 精选 留言 我的

精选列表

搜索[笔记],共9155篇文章
优秀的个人博客,低调大师

【Android学习笔记】设置App启动页

先将启动页放到项目资源中,图片一般是1080*1920的jpg。 新建一个activity,如图: 创建成功之后,打开刚刚创建的activity,来进行代码的编写: public class BZLaunchActivity extends AppCompatActivity { private final int SPLASH_DISPLAY_LENGHT = 2000;//两秒后进入系统,时间可自行调整 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_bzlaunch); //在BZLaunchActivity停留2秒然后进入BZLaunchActivity new android.os.Handler().postDelayed(new Runnable() { @Override public void run() { Intent mainIntent = new Intent(BZLaunchActivity.this,MainActivity.class); BZLaunchActivity.this.startActivity(mainIntent); BZLaunchActivity.this.finish(); } },SPLASH_DISPLAY_LENGHT); } } 然后去xml配置文件里画界面,配置文件在res/layout与创建时layout同名的的xml文件,代码如下: <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".BZLaunchActivity"> <ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" //让图片全屏显示 android:scaleType="fitXY" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" //启动页图片 app:srcCompat="@mipmap/zqq_launch" /> </android.support.constraint.ConstraintLayout> 如果android:scaleType="fitXY"不设置,可能出现启动页图片不全屏的情况。 最后要去AndroidManifest.xml文件中修改一下启动页的activity的位置,未修改之前,MainActivity是在前面的,这个时候运行App,发现并没有启动页,我们需要把启动页的activity调到MainActivity的前面,也就是: <activity android:name=".BZLaunchActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> 好了,完成上面这些,再运行App,就会看到启动页了。

优秀的个人博客,低调大师

【Android学习笔记】设置项目桌面icon

近来项目处于测试阶段,工作少了许多,就装了个最新的Android Studio,想写一下安卓。新建好项目,想设置个桌面的icon。我先准备好自己的icon图片,然后复制粘贴到res/mipmap-hdpi文件夹下,然后在AndroidManifest中将icon的地址改为我自己图片的命名,运行之后,发现模拟器所有icon都是圆的,我的图片是方形的,显示的样子为一个圆的白色里面套着我的方形icon,然后就上网查了一下安卓icon适配的问题。Android Studio确实也提供了适配的方法,网上也有很多,不过我掉进了一个坑里,先来介绍下icon自适应的配置,首先新建一个Image Asset,如图: 选择Image Asset之后, 如图在标注的地方选择自己要设置的icon的图片。前面我说过,我已经将icon复制到res/mipmap-hdpi文件夹,然后我去那里选择图片,但是并没有我粘贴进去的图片,然后我直接右键res/mipmap-hdpi文件夹,选择显示文件夹,就看到图片在那里。也就是在设置icon选择路径那里选不到自己的icon,然后弄了好久,icon一直设置不成功,最后我在路径那里选了那张图片在我电脑上的路径,然后就发现右边图片不再显示默认的icon而是我自己的icon了,然后点击next,再点击finish,App的icon就设置好了。 说一下主要坑点,icon图片已经复制粘贴到项目下,但是在选择图片的时候去到图片所在的路径却看不到图片。如果遇到这种情况,就不要先把图片放到项目里,设置的时候直接选择图片就可以了。 由于做安卓开发不久,处于菜鸟阶段,我不知道这是什么原因造成的,有路过的大神可以给我解答一下疑惑。另外我之前用过Android Studio2.x的版本,设置icon的时候就没遇到过这个问题。

优秀的个人博客,低调大师

Django学习笔记-定时器 CRONTAB

一、Introduction 二、Backgoround 三、CRONTAB 1.安装 2.配置 3.添加定时任务 4.启动任务 四、结束 五、参考 一、Introduction 在官网上的说明: dead simple crontab powered job scheduling for django 英语不好的我只是认为crontab能给django提供一个按照时间进行的作业调度的功能。 二、Backgoround 在做网站的时候,往往需要在某个固定的时间点,或者某个固定的时间间隔自动的触发一个事件,进行一些操作。比如每个月的财务报表在月末的时候会自动生成,然后发一个账单到你的email中。 针对这个需求,我们就要使用crontab实现定时器的功能。 但是在django中实现定时器的工具有好几种,我们使用crontab是因为它比较简单,易于使用。 celery也可以实现这个功能,这里就不讨论了。 但是crontab有个缺点: 就是他不支持在windows使用。不过幸好博主就是在linux上开发的。 三、CRONTAB 话不多说,开始使用crontab吧。 1.安装 pip install django-crontab 2.配置 在setting.py中的INSTALLED_APPS加入django_crontab INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_crontab', ] 3.添加定时任务 在app中的xxx.py中加入task()函数 # 某个app/xxx.py def task(): #定时任务 ··· 同时要在setting.py中添加这个定时任务 CRONJOBS = [ # 每一分钟执行一次 ('*/1 * * * *', 'app名称.xxx.task') ] 具体参数解释: 前5个(*)星号: M(分钟0-59) H(小时0-23) D(天1-31) m(月1-12) d(一星期内的天0-6,0为星期天) 特殊符号: * 代表所有的取值范围的数字 / 代表每的意思,*/5就是每5个单位 - 代表从某个数字到某个数字 , 分开几个离散的数字 举个列子: 每两个小时 0 /2 * * 晚上11点到早上8点之间每两个小时,早上8点 0 23-7,8 * * * 每个月的4号和每个礼拜的礼拜一到礼拜三的早上11点 0 11 4 * 1-3 1月1日早上4点 0 4 1 1 * 4.启动任务 # 将任务添加并生效 python manage.py crontab add # 显示当前的定时任务 python manage.py crontab show # 删除所有定时任务 python manage.py crontab remove # 只运行定时任务试一试 python manage.py crontab run 注意: 当添加一个定时任务后: 得到了一个hash值,所以在进行run的时候: python manage.py crontab run 2fc2215151a785c33b28c74ad5feb636 就像git一样 除此之外,要有查看crontab的文件的命令:corntab -e 四、结束 运行这个项目就会定时触发事件,执行你要的代码了。 当然要是仅仅输出一些东西,运行的时候是看不到的。 打印log,传参等等这里就不赘述了。如图 五、参考 https://github.com/kraiz/django-crontab https://pypi.python.org/pypi/django-crontab

优秀的个人博客,低调大师

Docker技术笔记:Ubuntu安装Docker CE

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhaobryant/article/details/79600050 安装环境 操作系统:Ubuntu Xenial 16.04 (LTS) Go语言版本:1.9.4 配置Ubuntu更新源(清华大学) $ sudo vim /etc/apt/sources.list # deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security universe deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security multiverse 卸载旧版本的Docker $ sudo apt-get remove docker docker-engine docker.io 安装新版本的Docker 步骤一:安装必要的系统工具 $ sudo apt-get update $ sudo apt-get -y install apt-transport-https ca-certificates curl software-properties-common 步骤二:安装GPG证书 $ curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add - 步骤三:写入软件源信息 $ sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" 步骤四:更新并安装Docker-CE $ sudo apt-get -y update $ sudo apt-get -y install docker-ce 附:安装指定版本的Docker-CE # Step 1: 查找Docker-CE的版本: $ apt-cache madison docker-ce docker-ce | 17.03.1~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages docker-ce | 17.03.0~ce-0~ubuntu-xenial | http://mirrors.aliyun.com/docker-ce/linux/ubuntu xenial/stable amd64 Packages # Step 2: 安装指定版本的Docker-CE: (VERSION 如上 17.03.1~ce-0~ubuntu-xenial) $ sudo apt-get -y install docker-ce=[VERSION] 配置阿里云镜像加速器 需登录阿里云管理控制台,获取专属的加速器地址。 针对Docker客户端版本大于1.10.0的用户,可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器: $ sudo mkdir -p /etc/docker $ sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://irnlfwui.mirror.aliyuncs.com"] } EOF $ sudo systemctl daemon-reload $ sudo systemctl restart docker 测试Docker版本(验证安装是否成功) 命令:docker –version && docker version && docker info $ sudo docker --version Docker version 17.12.1-ce, build 7390fc6 $ sudo docker version Client: Version: 17.12.1-ce API version: 1.35 Go version: go1.9.4 Git commit: 7390fc6 Built: Tue Feb 27 22:17:40 2018 OS/Arch: linux/amd64 Server: Engine: Version: 17.12.1-ce API version: 1.35 (minimum version 1.12) Go version: go1.9.4 Git commit: 7390fc6 Built: Tue Feb 27 22:16:13 2018 OS/Arch: linux/amd64 Experimental: false $ sudo docker info Containers: 3 Running: 0 Paused: 0 Stopped: 3 Images: 6 ... 测试Docker安装 可以通过运行简单的Docker Image来进行安装测试: $ sudo docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest: sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b9559b27182d3fa80ce3f7 Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. ... 列出所有的镜像image和容器container: $ sudo docker images REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest f2a91732366c 3 months ago 1.85kB $ sudo docker container ls -all CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES c621f40a070c hello-world "/hello" 15 minutes ago Exited (0) 15 minutes ago friendly_edison Recap and Cheat Sheet ## List Docker CLI commands docker docker container --help ## Display Docker version and info docker --version docker version docker info ## Excecute Docker image docker run hello-world ## List Docker images docker image ls ## List Docker containers (running, all, all in quiet mode) docker container ls docker container ls --all docker container ls -a -q ## Stop all Docker containers docker stop $(docker ps -a -q) ## Remove all Docker containers docker rm $(docker ps -a -q) ## Remove specific Docker image docker rmi <image_id> ## Remove all untagged Docker images (id is <none>) docker rmi $(docker images | grep "^<none>" | awk "{print $3}") ## Remove all Docker images docker rmi $(docker ps -a -q) 参考资料 其他关于旧版本Docker卸载以及测试开发版本Docker安装的帮助,可以参考官方文档的说明进行安装。 Ubuntu中安装Docker帮助链接

优秀的个人博客,低调大师

Java-学习笔记-4-抽象

不足之处,欢迎专家、同行、读者批评指正。 上一篇在说类库文件时提到了封装,不够严谨,这一篇来简单讲讲。 抽象和封装,这是面向对象程序设计中的一个重要思想。换句话说,是思维方式的转变。以前我们编程,是围绕某一个问题的,研究它的过程是怎样的。现在嘛,是考虑不同的对象之间的信息传递,更适合来写不同对象交互信息的业务。 先说说抽象。最关键的在于属性和功能。举个例子吧,比如说现在你要去图书馆借书,那对你来说,你的属性就是个人ID,借阅权限,借了几本书等等,图书馆那边对象很多,比如说管理员、书等等。你们之间的业务往来,就可以看作功能。 更直白点说,属性通常就是信息的那个值,编程时我们写成int的这种,所谓的功能就是对这个值进行操作的函数或者说方法。当然啦,一个类之中嵌套另一个类,并且把里边的那个类看做是成员变量,这种情况也是有的,不过在理解含义时可以把它和上文的“值”看作一回事。

优秀的个人博客,低调大师

Java-学习笔记-5-封装

不足之处,欢迎专家、同行、读者批评指正。 抽象和封装其实可以放到一起来记。 封装,字面意思看起来像是封上口打包装起来——实际上就是这个意思。只不过,这里我们打包的不是快递包裹,是代码的源文件。Java是有包管理机制的。 这个包,在资源管理器里看的话,是一个个的文件夹——但反过来不能说文件夹就是包。你看,封装,打包,命名的时候就是这么直白。 这个机制,是对访问权限的限制。不过它限制的不是我们。作为开发者,我们自己所负责的几个包中,所有代码都是可以看到的。但是,它限制了不同包的源文件中的变量或者方法,访问其他源文件中的变量或者方法的权限。 关于这个,和C++相似,但不一样。具体可以查阅文档。搜索的关键字可以是public、private等。 是的,文档永远是第一手信息。

优秀的个人博客,低调大师

Java-学习笔记-6-继承

不足之处,欢迎专家、同行、读者批评指正。 我们写代码,当然是希望越简单越好——这个简单是说简洁没有废话,但也不是极端的少,而是必须便于理解,不是秀操作的那种一行写完原本十行的逻辑,让别人读起来像做解谜游戏一样。 继承就有这个好处。 在面向对象的思想中,我们操作的是一个个的对象。如果对象之间有从属关系,我们再去写其中相同的内容,岂不是很多余?这时候就该用上继承了。 当然,继承的作用远不止如此。 继承、多态、某种角度还可能要算上接口,这些是需要打通理解的知识点。

优秀的个人博客,低调大师

Java-学习笔记-7-多态

不足之处,欢迎专家、同行、读者批评指正。 关于多态,我在学的时候遇到了不同的划分范畴的说法。一种理解是,子类对象分别各自实现父类对象的同一个方法。而我本科所用的教材,则是说这个有子类对象作为父类对象引用、子类对父类方法的覆盖、同一个类中方法的覆盖。(因为这个是之前面试时我和面试官分歧的地方,所以印象深刻,他持第一种观点,认为我提到的“同一个类中方法的覆盖”这个不是多态) 之前写了几篇文章,似乎没什么人关注。如果有人关注的话,稍后我会补上自己总结的用来理解的代码示例。

优秀的个人博客,低调大师

Java-学习笔记-8-接口

不足之处,欢迎专家、同行、读者批评指正。 Java在设计的时候为了求简,是舍弃了多继承机制的。但是,实际开发中有时候又需要用。于是,开发者们就曲线救国,通过接口来变相地实现多继承。 其实我个人也比较赞同单继承。接口和继承,是两个不同层次的概念,本来不应该相提并论的。不过在使用时,比较接近。 今天太晚了,先写到这里。如果有人关注的话,稍后我会补上更多的理解。

优秀的个人博客,低调大师

Java-学习笔记-1-概述

不足之处,欢迎专家、同行、读者批评指正。 源起 Java语言的前身是oak语言——oak是在1991年诞生于Sun公司的研究项目,由 James Goslingt 和 Patrick naughton 这两位大牛负责。这个项目最初是为了给消费级电子设备(通俗点说就是家用电器)提供一个通用的开发环境,结果并不成功。这个不成功说的是这个项目它不赚钱,不是说这个oka没开发出来。 简单说一下这个oka。一开始他们本来是打算用c++的,但是C++的安全性差。所以他们就参考C++开发了一个新语言,oak。也就是C特性的一些语法,加上安全性方面的机制。 回来接着说这个项目。正所谓乱世出英雄,这个生不逢时的oak项目,在互联网时代迎来了曙光。因为它的三大特性:跨平台、面向对象、安全性高,正好符合互联网的需要。跨平台,这个是他们一开始就设计好的,因为当初就是为了解决不同设备的通用环境问题。面向对象,这个是C++的特性。安全性,这个是他们自己补充的。但是oak不是拿来就能在Internet上直接用的,所以他们就结合互联网的需求,重新设计了一下oak,最后把它取名叫做Java——没错,就是爪哇,图标都配的是当地特产咖啡。这是在1995年,Java正式面世。 Java与C++的比较 先说它们两个的相同点:它们都是面向对象的——Java当初在设计的时候就向C++借鉴了这一点。所以他们在语法上也非常相似。 接下来再说说它们的不同点。它们最大的不同就是:Java不支持指针,而C++是支持指针的。指针对于编程新手来说,非常的不友好。甚至可能在开发的过程中造成严重的后果。而Java由于不支持指针,从一开始就限制了程序员不能使用指针,主动避免了这个问题。所以说Java比C++简单了很多。这也是Java广受欢迎,应用广泛的原因之一。 第二个不同点。Java 需要被编译成虚拟机的字节码,通过虚拟机来运行。而C++则是直接编译成机器码,然后直接运行。由此可以看出,Java的运行效率是不如C++的。 第三个不同点。Java 中最基本的数据类型都有规定的字节大小。而C++中数据类型的字节大小,要看它具体是怎么实现的。Java中所有对象都是按引用传递的。而C++中的对象都是按值传递的。 第四个不同点。C++保留了许多 C 的功能,这些是面向底层的。Java 中去除了这些功能。同时,Java 用垃圾回收代替了程序员自己释放内存,还放弃了运算符重载和多重继承等这些c++的功能。但在Java的实际编程操作中,我们可以利用接口来实现有限制的多重继承。 第五个不同点。Java更关注的是安全性,可移植性和快速开发。C++则是关注性能和对C向下兼容。

优秀的个人博客,低调大师

NLTK基础教程学习笔记(十三)

在信息摘要应用中还包含着另一种理论逻辑:重要的句子中通常包含着重要的词汇,而跨语料库的差异词(discriminatory word)绝大多数数是重要词汇。因此,句子中包含具有差异很大的词汇,它就很重要。这样就得到一个非常简单的测量方法,就是计算每一个词各种的TF-IDF(term frequency-inverse document )分值,然后根据词汇的重要性找出一种标准化的凭据评分。这个评分就可以用来充当在信息摘要中选取句子的标准。 TF-IDF(term frequency–inverse document frequency)是一种用于资讯检索与资讯探勘的常用加权技术。TF-IDF是一种统计方法,用以评估一字词对于一个文件集或一个语料库中的其中一份文件的重要程度。字词的重要性随着它在文件中出现的次数成正比增加,但同时会随着它在语料库中出现的频率成反比下降。TF-IDF加权的各种形式常被搜寻引擎应用,作为文件与用户查询之间相关程度的度量或评级。除了TF-IDF以外,因特网上的搜寻引擎还会使用基于连结分析的评级方法,以确定文件在搜寻结果中出现的顺序。按照其不拿整段介绍来做,只拿前三句来实践,我拿了前一段: import nltk from sklearn.feature_extraction.text import TfidfVectorizer f=open('news.txt') news_content=f.read() results=[] sentences=nltk.sent_tokenize(news_content) vectorizer=TfidfVectorizer(norm='l2',min_df=0,use_idf=True,smooth_idf=False,sublinear_tf=True) sklearn_binary=vectorizer.fit_transform(sentences) print(vectorizer.get_feature_names()) print(sklearn_binary.toarray()) 结果: ['accept', 'accepting', 'altria', 'and', 'announce', 'approaches', 'arthur', 'as', 'at', 'be', 'birth', 'britain', 'british', 'by', 'caliburn', 'ceremonial', 'character', 'decides', 'despite', 'destined', 'dies', 'draws', 'ector', 'eligible', 'embedded', 'enters', 'entrusted', 'explaining', 'fearing', 'fifteen', 'following', 'for', 'full', 'gender', 'growing', 'hardships', 'heir', 'her', 'hesitation', 'his', 'however', 'if', 'in', 'inspired', 'invasion', 'is', 'king', 'knight', 'known', 'large', 'leadership', 'leaving', 'legends', 'legitimate', 'loyal', 'mantle', 'merlin', 'monarch', 'name', 'nativity', 'never', 'no', 'not', 'of', 'or', 'pendragon', 'people', 'period', 'preserving', 'publicly', 'pulling', 'raises', 'recognize', 'responsible', 'ruler', 'saber', 'saxons', 'she', 'shoulders', 'sir', 'slab', 'son', 'soon', 'stone', 'subjects', 'surrogate', 'sword', 'symbolic', 'that', 'the', 'this', 'threat', 'throne', 'to', 'turmoil', 'uther', 'welfare', 'when', 'who', 'will', 'withdraws', 'without', 'woman'] [[ 0. 0. 0.15095332 0. 0. 0. 0.31622502 0. 0. 0. 0. 0. 0. 0.20340954 0. 0. 0.31622502 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.31622502 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.31622502 0. 0.17386773 0.24504638 0. 0. 0. 0. 0. 0.31622502 0. 0. 0. 0. 0. 0.31622502 0. 0. 0. 0. 0.15095332 0. 0.31622502 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.31622502 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.15095332 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ] [ 0.23250474 0. 0.11098857 0. 0.23250474 0. 0. 0.14955705 0.23250474 0. 0.23250474 0. 0. 0. 0. 0. 0. 0.23250474 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.23250474 0. 0. 0. 0. 0.18017058 0. 0. 0. 0.11098857 0. 0.23250474 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.23250474 0. 0. 0. 0. 0. 0.23250474 0.23250474 0. 0.23250474 0. 0.23250474 0. 0. 0. 0. 0.23250474 0. 0. 0. 0. 0.18017058 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.23250474 0. 0. 0. 0. 0. 0. 0. 0. 0.14955705 0. 0.18017058 0. 0. 0. 0.14955705 0. 0. 0.23250474] [ 0. 0. 0. 0. 0. 0. 0. 0.18736875 0. 0. 0. 0. 0. 0.18736875 0. 0. 0. 0. 0. 0. 0. 0. 0.29128766 0. 0. 0. 0.29128766 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.13904921 0. 0. 0. 0. 0. 0. 0. 0.1601566 0. 0.29128766 0. 0. 0. 0. 0. 0. 0.29128766 0. 0.22572213 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.29128766 0. 0. 0. 0. 0. 0.18736875 0. 0.29128766 0. 0.29128766 0. 0. 0. 0.29128766 0. 0. 0. 0. 0. 0. 0. 0.18736875 0. 0. 0. 0. 0.29128766 0. 0. 0. 0. ] [ 0. 0. 0.14155101 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.29652856 0. 0. 0.29652856 0. 0. 0. 0. 0. 0.29652856 0. 0. 0. 0. 0. 0. 0.29652856 0. 0. 0. 0. 0. 0. 0. 0. 0.16303816 0.22978336 0. 0.29652856 0. 0. 0.29652856 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.29652856 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.14155101 0. 0. 0.29652856 0.19073992 0. 0.22978336 0. 0.29652856 0. 0. 0. 0. 0. ] [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.24121053 0. 0.20022545 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.31127497 0. 0. 0. 0. 0.31127497 0. 0. 0. 0.31127497 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.31127497 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.25158536 0. 0. 0. 0.31127497 0. 0. 0. 0. 0. 0. 0. 0. 0.31127497 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.25158536 0. 0.31127497 0. 0. 0.31127497 0. 0. 0. 0. 0. 0. 0. 0. ] [ 0. 0. 0.10632924 0. 0. 0.22274414 0. 0.14327861 0. 0. 0. 0. 0.22274414 0. 0.17260697 0.22274414 0. 0. 0. 0.22274414 0. 0. 0. 0. 0.22274414 0. 0. 0.22274414 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.10632924 0. 0. 0. 0.22274414 0.22274414 0. 0. 0. 0. 0. 0. 0.22274414 0. 0. 0. 0. 0. 0. 0.17260697 0. 0. 0. 0. 0. 0. 0.10632924 0. 0. 0.17260697 0. 0. 0. 0. 0. 0.22274414 0. 0.17260697 0. 0. 0.14327861 0. 0. 0.22274414 0. 0.22274414 0.22274414 0. 0. 0.17260697 0. 0.22274414 0.10632924 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.14327861 0.22274414 0. 0. ] [ 0. 0.24521796 0.11705736 0.19002219 0. 0. 0. 0. 0. 0.24521796 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.24521796 0. 0. 0. 0.24521796 0. 0.11705736 0. 0. 0.24521796 0. 0. 0. 0. 0.13482643 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.24521796 0. 0. 0. 0. 0. 0.24565801 0. 0. 0.19002219 0. 0.24521796 0. 0.24521796 0. 0. 0.24521796 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.19002219 0.24521796 0. 0.19819534 0.24521796 0. 0. 0. 0. 0. 0.24521796 0. 0. 0.15773474 0. 0. 0. ] [ 0. 0. 0. 0.38872173 0. 0. 0. 0. 0. 0. 0. 0.22958532 0. 0. 0.22958532 0. 0. 0. 0.29627299 0. 0. 0.29627299 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.22958532 0. 0. 0. 0.14142901 0.29627299 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.29627299 0. 0. 0. 0. 0.29627299 0. 0. 0. 0. 0. 0. 0. 0.14142901 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.19057553 0.29627299 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.29627299 0. ]]

优秀的个人博客,低调大师

NLTK基础教程学习笔记(十二)

构建第一个NLP应用:信息摘要:对所提供的文章短文故事生成需要针对其内容自动生成摘要。信息摘要需要理解的不只是句子的结构,而是整个文本结构,还要了解文本的体裁和主体主题内容。下面了一个介绍创建个人版的Google News通常用于较多实体和名词的句子的重要性往往会比较高,现在的任务是要用某种可能被标准化的统一逻辑来计算重要性成分(importance score),即如果想要获取前n个句子的信息情况,要去选择一个重要性评分阈值。由于找不到原文的新闻材料所以用wiki上的一段介绍吾王Saber材料代替; f=open('new.txt','r') new_content=f.read() print(new_content) 结果: Saber's full name is Altria Pendragon, a character inspired by the legends of King Arthur. At her nativity, Uther decides to not publicly announce Altria's birth or gender, fearing his subjects will never accept a woman as a legitimate ruler. She is entrusted by Merlin to a loyal knight, Sir Ector, who raises her as a surrogate son. When Altria is fifteen, King Uther dies leaving no known eligible heir to the throne. Britain enters a period of turmoil following the growing threat of invasion by the Saxons. Merlin soon approaches Altria, explaining that the British people will recognize her as a destined ruler if she withdraws Caliburn, a ceremonial sword embedded in a large slab of stone. However, pulling this sword is symbolic of accepting the hardships of a monarch, and Altria will be responsible for preserving the welfare of her people. Without hesitation and despite her gender, she draws Caliburn and shoulders Britain's mantle of leadership. Altria rules Britain from her stronghold in Camelot and earns the reputation of a just, yet distant king. Under the guidance of Merlin and with the aid of her Knights of the Round Table, she guides Britain into an era of prosperity and tranquillity. Caliburn is destroyed, but Altria soon acquires her holy sword, Excalibur, and Avalon, Excalibur's blessed sheath, from Vivian, the Lady of the Lake. While Avalon is in her possession, Altria never ages and is immortal in battle. Despite her immense strength and fighting abilities, Altria is plagued by feelings of guilt and inferiority throughout her reign; she sacrifices her emotions for the good of Britain, yet many of her subjects and knights become critical of her lack of humanity and cold calculation. Excalibur's scabbard is stolen while she repels an assault along her country's borders; when Altria returns inland, she discovers Britain is being torn asunder by civil unrest. Despite her valiant efforts to placate the dissent, Altria is mortally wounded by a traitorous knight, a homunculus born of her blood named Mordred, during the Battle of Camlann. Her dying body is escorted to a holy isle by Morgan le Fay and Sir Bedivere. Altria orders a grieving Bedivere to dispose of Excalibur by throwing it back to Vivian; in her absence, she reflects on her personal failures, regretting her life as king. Before her last breath, she appeals to the world; in exchange for services as a Heroic Spirit, she asks to be given an opportunity to relive her life, where someone more suitable and effective would lead Britain in her stead. 要对文字进行分析,先要将文章转换成一个句子列表。用句子标识器将内容分成若干个句子,这里提供一些句型的编号,便于识别这些句子并对其进行排名。一旦得到了这些段子,会让其在单词标识器中过一遍,最后再来过NER标注器和POS标注器。 import nltk f=open('new.txt','r') new_content=f.read() results=[] for sent_no,sentence in enumerate(nltk.sent_tokenize(new_content)): no_of_tokens=len(nltk.word_tokenize(sentence)) #print(no_of_tokens) tagged=nltk.pos_tag(nltk.word_tokenize(sentence)) no_of_nouns=len([word for word ,pos in tagged if pos in ["NN","NNP"]]) ners=nltk.ne_chunk(nltk.pos_tag(nltk.word_tokenize(sentence))) no_of_ners=len([chunk for chunk in ners if hasattr(chunk,'label')]) score=(no_of_ners+no_of_nouns)/float(no_of_tokens) results.append((sent_no,no_of_tokens,no_of_ners,no_of_nouns,score,sentence)) for sent in sorted(results,key=lambda x:x[4],reverse=True): print(sent[5]) 上面代码中我们对句子列表进行了迭代,并根据公式计算出了这些句子的评分,该公式只是个以被标识实体为分子,以普通标识词为分母的分子式,将这些结果创建成一个元组。降序排列后打印的结果: Caliburn is destroyed, but Altria soon acquires her holy sword, Excalibur, and Avalon, Excalibur's blessed sheath, from Vivian, the Lady of the Lake. Her dying body is escorted to a holy isle by Morgan le Fay and Sir Bedivere. Saber's full name is Altria Pendragon, a character inspired by the legends of King Arthur. Britain enters a period of turmoil following the growing threat of invasion by the Saxons. Altria rules Britain from her stronghold in Camelot and earns the reputation of a just, yet distant king. Without hesitation and despite her gender, she draws Caliburn and shoulders Britain's mantle of leadership. Under the guidance of Merlin and with the aid of her Knights of the Round Table, she guides Britain into an era of prosperity and tranquillity. While Avalon is in her possession, Altria never ages and is immortal in battle. Excalibur's scabbard is stolen while she repels an assault along her country's borders; when Altria returns inland, she discovers Britain is being torn asunder by civil unrest. Despite her valiant efforts to placate the dissent, Altria is mortally wounded by a traitorous knight, a homunculus born of her blood named Mordred, during the Battle of Camlann. When Altria is fifteen, King Uther dies leaving no known eligible heir to the throne. She is entrusted by Merlin to a loyal knight, Sir Ector, who raises her as a surrogate son. Merlin soon approaches Altria, explaining that the British people will recognize her as a destined ruler if she withdraws Caliburn, a ceremonial sword embedded in a large slab of stone. Altria orders a grieving Bedivere to dispose of Excalibur by throwing it back to Vivian; in her absence, she reflects on her personal failures, regretting her life as king. At her nativity, Uther decides to not publicly announce Altria's birth or gender, fearing his subjects will never accept a woman as a legitimate ruler. Before her last breath, she appeals to the world; in exchange for services as a Heroic Spirit, she asks to be given an opportunity to relive her life, where someone more suitable and effective would lead Britain in her stead. Despite her immense strength and fighting abilities, Altria is plagued by feelings of guilt and inferiority throughout her reign; she sacrifices her emotions for the good of Britain, yet many of her subjects and knights become critical of her lack of humanity and cold calculation. However, pulling this sword is symbolic of accepting the hardships of a monarch, and Altria will be responsible for preserving the welfare of her people. 完成了句子的排序,一旦有no_of_nouns和no_of_ners的评分列表,就可以围绕他们建议一些更加复杂的规则。

优秀的个人博客,低调大师

NLTK基础教程学习笔记(十一)

语块分解例子: from nltk.chunk.regexp import * import nltk test_sent="The prime minister announced he had asked the chief government whip, Philip Ruddock, to call a special party room meeting for 9am on Monday to consider the spill motion." test_sent_pos=nltk.pos_tag(nltk.word_tokenize(test_sent)) rule_vp=ChunkRule(r'(<VB.*>)?(<VB.*>)+(PRP)?','Chunk VPs') parser_vp=RegexpChunkParser([rule_vp],chunk_label='VP') print(parser_vp.parse(test_sent_pos)) rule_np=ChunkRule(r'(<DT>?<RB>?)?<JJ|CD>*(<JJ|CD><,>)*(<NN.*>)+','Chunk NPs') parser_np=RegexpChunkParser([rule_np],chunk_label="NP") print(parser_np.parse(test_sent_pos)) 结果: (S The/DT prime/JJ minister/NN (VP announced/VBD) he/PRP (VP had/VBD asked/VBN) the/DT chief/JJ government/NN whip/NN ,/, Philip/NNP Ruddock/NNP ,/, to/TO (VP call/VB) a/DT special/JJ party/NN room/NN meeting/NN for/IN 9am/CD on/IN Monday/NNP to/TO (VP consider/VB) the/DT spill/NN motion/NN ./.) (S (NP The/DT prime/JJ minister/NN) announced/VBD he/PRP had/VBD asked/VBN (NP the/DT chief/JJ government/NN whip/NN) ,/, (NP Philip/NNP Ruddock/NNP) ,/, to/TO call/VB (NP a/DT special/JJ party/NN room/NN meeting/NN) for/IN 9am/CD on/IN (NP Monday/NNP) to/TO consider/VB (NP the/DT spill/NN motion/NN) ./.) 上述代码是用来对动词,和名词进行划分操作,语块分解过程中会有一条管道,作用his标记POS标签,并为相关的语块分解器提供输入字符串,这里使用的是普通的语块分解器,其中的NP、VP规则定义了各种不同的可被称为动词与名词短语的POS模式。例如,NP规则定义的是所有以限定词开头,后接一个副词、形容词或纯数字的可被分解成一个名词短语的组合,这种基于一个表达式的语块分解器得依靠手动涉及分块字符串来定义分块规则。但普适式的规则很难找到。另一种方法是用机器学习的方法来进行语块的分解。信息提取:介绍了如何用NLTK库来开发一个信息提取(IE)引擎。一个典型的信息抽取管道在结构上都是非常类似的具体如下图:命名实体识别(NER)从本质上讲NER是一种提取信息的方式,它提取的是一些最常见的实体信息,如实体名词,所属的组织,以及所在的位置等。某些NER也可用于提取一般实体,如产品名词,生物医学项目、作者姓名、品牌名等。下面是一个例子: import nltk f=open('nerdemo.txt') text=f.read() sentences=nltk.sent_tokenize(text) tokenized_sentences = [nltk.word_tokenize(sentence) for sentence in sentences] tagged_sentences = [nltk.pos_tag(sentence) for sentence in tokenized_sentences] for sent in tagged_sentences: print(nltk.ne_chunk(sent)) 结果: (S I/PRP want/VBP the/DT (GPE Cherry/NNP) keyboard/NN) 上面代码按照之前的相同管道流程走了一遍,执行了所有的预处理步骤,包括句子的标识化,词汇标识化、词性标注以及NLTK的NER(预训练模型)等用来提取所有NER的步骤。关系提取:关系提取是常用的信息提取操作。是提取不同实体之间不同的关系的过程,这里的关系可以根据信息的需要定义。下面的代码中,使用了ieer的内置语料库,会对句子进行NER标注,这里唯一需要做的是指定所需的关系模式,以及该关系所定义NER种类,下面代码中组织与位置之间的关系已经被定义好了,要要提取的是这些模式的所有组合。 import re import nltk IN = re.compile(r'.*\bin\b(?!\b.+ing)') for doc in nltk.corpus.ieer.parsed_docs('NYT_19980315'): for rel in nltk.sem.extract_rels('ORG', 'LOC', doc, corpus='ieer', pattern=IN): print(nltk.sem.rtuple(rel)) 结果: [ORG: 'WHYY'] 'in' [LOC: 'Philadelphia'] [ORG: 'McGlashan &AMP; Sarrail'] 'firm in' [LOC: 'San Mateo'] [ORG: 'Freedom Forum'] 'in' [LOC: 'Arlington'] [ORG: 'Brookings Institution'] ', the research group in' [LOC: 'Washington'] [ORG: 'Idealab'] ', a self-described business incubator based in' [LOC: 'Los Angeles'] [ORG: 'Open Text'] ', based in' [LOC: 'Waterloo'] [ORG: 'WGBH'] 'in' [LOC: 'Boston'] [ORG: 'Bastille Opera'] 'in' [LOC: 'Paris'] [ORG: 'Omnicom'] 'in' [LOC: 'New York'] [ORG: 'DDB Needham'] 'in' [LOC: 'New York'] [ORG: 'Kaplan Thaler Group'] 'in' [LOC: 'New York'] [ORG: 'BBDO South'] 'in' [LOC: 'Atlanta'] [ORG: 'Georgia-Pacific'] 'in' [LOC: 'Atlanta']

优秀的个人博客,低调大师

NLTK基础教程学习笔记(十)

依赖性文本解析:依赖性文本解析(dependency parsing 简称DP)是一种现代化的文本解析机制。DP的主要概念是将各个语法单元(单词)用丁香链路串联起来。这种链路称为依赖关系(dependencies)。在目前的文本解析社区中,有大量工作在进行。尽管短语结构式文本解析(phrase structure parsing)在异乡词序自由的语言(如捷克语和土耳其语)中被广泛使用,但依赖性文本解析别被证明是一种更为有效地方法。短语结构式文本解析与依赖性文本解析之间存在着一个明显的区别,从他们所产生的解析树上可以看出来。解析书上短语结构树试图捕捉的首先是单词与短语之间的关系,然后是短语与短语之间的关系,依存关系树只关心单词与单词之间的关系如big完全依赖于dog。NLTK库也提供了一些可用于执行依存性文本解析的方法。其中一个是使用基于概率的投射依存性解析器(probabilistic,projective dependency parser),但解析器得经由某个有限训练数据集来进行训练。依存性解析器的另一种形态就是Stanford解析器。下面是一个Stanford解析器的例子:语块分解:语块分解属于浅解析,目的是将句子分解成有意义的语块,将语块定义为文本解析中的最小单元,例如将“the President speaks about the health care reforms “句子分成两个语块。第一个语块“the President”该语块由名词主导,称为名词短语(NP),另一部分由动词主导称为动词短语。将句子划分成各个部分的过程就是语块分解。从形式上看语块分解操作也可以被看作是一种处理接口,作用是识别出文本中互相不重叠的部分。对于一些文本问题想只想提取其中的关键短语,命名实体或者先关项目的特定模式,在这种情况下要做浅解析非深解析,深解析回去处理所有违法语法规则的句子,也会产生不同的语法树,直到解析器在反复回溯的过程中找到最佳的解析树,整个过程非常耗时和繁琐,并且完成了所有的这些过程也未必会得到正确的解析树。而浅解析则可以用语块来保证其浅解析的结构,这种处理相对而言要较快一些。

优秀的个人博客,低调大师

NLTK基础教程学习笔记(七)

正则表达式标注器:定义了一个这则表达式的同时定义出给定表达式所对应的标签。下面会看到一些常见的正则表达式是如何获取不同词性的。其中有一些模式都有各自关联的POS类别。 from nltk.tag.sequential import RegexpTagger from nltk.corpus import brown brown_tagged_sents=brown.tagged_sents(categories='news') train_data=brown_tagged_sents[:int(len(brown_tagged_sents)*0.9)] test_data=brown_tagged_sents[int(len(brown_tagged_sents)*0.9):] regexp_tagger = RegexpTagger( [( r'^-?[0-9]+(.[0-9]+)?$', 'CD'), # cardinal numbers ( r'(The|the|A|a|An|an)$', 'AT'), # articles ( r'.*able$', 'JJ'), # adjectives ( r'.*ness$', 'NN'), # nouns formed from adj ( r'.*ly$', 'RB'), # adverbs ( r'.*s$', 'NNS'), # plural nouns ( r'.*ing$', 'VBG'), # gerunds (r'.*ed$', 'VBD'), # past tense verbs (r'.*', 'NN') # nouns (default) ]) print(regexp_tagger.evaluate(test_data)) 结果: 0.31306687929831556 这里应用一些基于POS的显模式能到到30%的正确率。通过BackoffTagger就有可能提高性能。尝试着通过UnigramTagger from nltk.tag.sequential import RegexpTagger from nltk.corpus import brown import nltk from nltk.tag import UnigramTagger brown_tagged_sents=brown.tagged_sents(categories='news') train_data=brown_tagged_sents[:int(len(brown_tagged_sents)*0.9)] test_data=brown_tagged_sents[int(len(brown_tagged_sents)*0.9):] regexp_tagger = RegexpTagger( [( r'^-?[0-9]+(.[0-9]+)?$', 'CD'), # cardinal numbers ( r'(The|the|A|a|An|an)$', 'AT'), # articles ( r'.*able$', 'JJ'), # adjectives ( r'.*ness$', 'NN'), # nouns formed from adj ( r'.*ly$', 'RB'), # adverbs ( r'.*s$', 'NNS'), # plural nouns ( r'.*ing$', 'VBG'), # gerunds (r'.*ed$', 'VBD'), # past tense verbs (r'.*', 'NN') # nouns (default) ]) Unigram_tagger=UnigramTagger(train_data,backoff=regexp_tagger) print(Unigram_tagger.evaluate(test_data)) 结果为: 0.8656433768563739 相较于之前的确有略微地提升Brill标注器:Bril标注器是一种基于转换操作的标注器,其思路是先对标签做一个猜想,然后在下一轮迭代中基于标注器接下来所学到的规则设置返回到原先的错误上并修复它。是一种半监督的标注方式,与N-gram不同的是后者会在训练过程中对N-gram模式来进行计数,这里我们要查找的是转换规则。基于机器学习的标注器:一些标注器内部都是黑盒子,如pos——tag内部使用的是最大熵分类器(MEC),StanfordTagger所采用的也是最大熵标注器但属于不同的模型。其中有很多是基于隐马尔科夫随机场(HMM)和条件随机场(CRF)的标注器都是生成模型。命名实体识别(NER):除了POS之外在文本中找出命名实体项也是最常见的标签化问题,通常情况下NER主要由实体、位置和组织构成。这也可以视为一个顺序化标签的问题,可以利用上下文语境和其他相关特性来标签化这些命名体。NLTK库中NER标注的方式有两种:1是基于事先标注好的NER模型2是建立一个机器学习的模型。NER标注器:NLTK提供的命名实体提取方式是ne_chunk().用一个例子来显示如何对任意的语句进行标注。这种方法需要先进性文本的预处理,即先对语句进行标识化处理,然后再进行语块分解和词性标注的处理顺序,之后才能进行命名实体的标注: import nltk from nltk import word_tokenize from nltk import ne_chunk Sent="Mark is studying at Standford University in California." print(ne_chunk(nltk.pos_tag(word_tokenize(Sent)),binary=False)) 结果: (S (PERSON Mark/NNP) is/VBZ studying/VBG at/IN (ORGANIZATION Standford/NNP University/NNP) in/IN (GPE California/NNP) ./.) 可以看到ne_chunking方法主要用于姓名,地点,如果binary设置True,给出句子树结构和标签。

优秀的个人博客,低调大师

NLTK基础教程学习笔记(八)

浅解析与深解析:通常情况下,在深入解析或者全面解析的过程中,像CFG(Context-Free Grammer,上下文无关语法),PCFG(即probabilistic context-free grammar,概率性上下文无关语法)以及搜索策略这样的语法概念的作用都是要将一套完整的语法结构运用的某个句子上。其中浅解析(shallow parsing)是一种面向给定文本的,对其语法信息部分控模型的有限解析任务。而深解析(deep parsing)则是一种更为复杂的应用。一般来说,深解析比较适合于对话系统和文本综述这样的应用场景,而浅解析更适合于信息提取和文本挖掘这一类的应用。两种解析方法:文本解析方法主要有两种,其具体情况如下所示:基于规则的方法:该方法基于规则和语法,在该方法中我们将会基于CFG等语法概念来撰写语法规则手册,是一种自上而下的方法,该方法中包含了CFG和基于表达式的解析器。基于概率的方法:在该方法中通过概率模型来学习规则和语法,该方法使用的是所观测到的相关语言特征的出现概率,是一个自下而上的方法,方法中包含了PCFG和stanford解析器。为什么要进行解析?编写解析器时,能提出一组可被当作某种模板的规则,这些规则就能按照某种适当的顺序写出句子。另外也需要将单词分门别类即进行词性的标注。下面是一个用CFG的例子: import nltk toy_grammar=nltk.CFG.fromstring( """ S -> NP VP VP -> V NP V -> "eats" | "drinks" NP -> Det N Det -> "a" | "an" | "the" N -> "president" |"Obama" |"apple"| "coke" """) print(toy_grammar.productions()) 结果: [S -> NP VP, VP -> V NP, V -> 'eats', V -> 'drinks', NP -> Det N, Det -> 'a', Det -> 'an', Det -> 'the', N -> 'president', N -> 'Obama', N -> 'apple', N -> 'coke'] 目前这一语法概念所能产生的句子数量有限。如果出现知道如何一个名词和一个动词搭配使用,并且这些动词和名词只能来自于上述代码所列出的单词,那么大概可以搭配出这样的列句。President eats appleObama drinks coke显然我们运用所学的英语语法规则造出句子,理解也是相同的规则,但在这些规则显然不适用于莎士比亚时期所用的文体。而且同一套语法也可能会构造出一些毫无意义的句子如:Apple eats coke.President drinks Obama.当涉及到某个语法解析器时(syntactic parser)时,事实上本身就有一定的几率在语法上形成一些毫无意义的句子。如果想要获取其中的语义的话,就需要对句子有一个更深入的理解。

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码