首页 文章 精选 留言 我的

精选列表

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

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)时,事实上本身就有一定的几率在语法上形成一些毫无意义的句子。如果想要获取其中的语义的话,就需要对句子有一个更深入的理解。

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

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

用NLYK库实现标注任务的方式有两种:1:使用NLTK库或其他库中的预置标注器,并将其运用到测试数据上。这两种标注器应该足以应对英语文本环境,以及非特殊领域语料库中的所有词性标注任务。2:基于测试数据来创建或训练出适合的标注器。深入了解标注器:一个典型的标注器通常要用到大量的训练数据,它主要被用于标注出句子中的各种单词,并为其贴上POS标签。标注是一个纯手工的工作,具体如下: Well/UH what/WP do/VBP you/PRP think/VB about/IN the/DT idea/NN of/IN... 以上是来自Penn Treebank的语义库。其中还有一个语言数据联盟(LDC)专门用来研究不同语言的标注,不同文本种类以及不同标注操作,如词性标注,句法分析标注,以及对话标注等。通常情况下,像词性标注这样的标注问题往往会被视为顺序标签化的问题或者某种分类问题,后者特指人们为特定token所生成的正确标签,并用先关判别模型对其进行判别的一类问题。下面是分析Brown语料库中各POS标签的分布频率: from nltk.corpus import brown import nltk tags=[tag for (word,tag)in brown.tagged_words(categories='news')] print(nltk.FreqDist(tags)) out=nltk.FreqDist(tags) 结果: <FreqDist with 218 samples and 100554 outcomes> 由于个数太多无法打印,可以通过debug进去看各个词的的频率。Debug进去看可以看到NN在这里出现频率最高,可以用来创建一个POS标注器,用来给所有的测试文本分配NN标签。DefaultTagger函数是顺序性标注器,标注器会去调用evaluate()函数,该函数主要用来评估相关单词POS的准确度,是对Brown语料库的标注器所用的基准: from nltk.corpus import brown import nltk brown_tagged_sents=brown.tagged_sents(categories='news') default_tagger=nltk.DefaultTagger('NN') print(default_tagger.evaluate(brown_tagged_sents)) 结果: 0.13089484257215028 准确率大概13%左右DefaultTagger的表现并不是很好,DefaultTagger本质上只是基类SequentialBackoffTagger的一部分,后者是一个顺序性标注服务。标注器会试着基于其所处的上下文环境来模型化先关的标签。而且如果它不能进行正确的标签预测,就会去咨询BackoffTagger。通常情况下,DefaultTagger参数都可以被当作一个BackoffTagger实体来使用。N-gram标注器 from nltk.tag import UnigramTagger from nltk.tag import DefaultTagger from nltk.tag import BigramTagger from nltk.tag import TrigramTagger from nltk.corpus import brown import nltk brown_tagged_sents=brown.tagged_sents(categories='news') default_tagger=nltk.DefaultTagger('NN') train_data=brown_tagged_sents[:int(len(brown_tagged_sents)*0.9)] test_data=brown_tagged_sents[int(len(brown_tagged_sents)*0.9):] unigram_tagger=UnigramTagger(train_data,backoff=default_tagger) print(unigram_tagger.evaluate(test_data)) bigram_tagger=BigramTagger(train_data,backoff=unigram_tagger) print(bigram_tagger.evaluate(test_data)) trigram_tagger=TrigramTagger(train_data,backoff=bigram_tagger) print(trigram_tagger.evaluate(test_data)) 结果: 0.8368384331705372 0.8460081730290043 0.8439150802352238 其中,基于元模型的标注只考虑相关标签的条件概率,以及针对每个给定token所能预测到的、频率最高的标签。而bigram-tagger参数将会考虑给定的单词和该单词的前一个单词,其标签将以元组的形式来关联被测试单词所得到的标签。类似的,TrigramTagger参数将让其查找过程兼顾到给定单词的前两个单词。TrigramTagger参数的覆盖范围比较小,而实例精度则高一些。从另一方面来说,UnigramTagger的覆盖范围则会大一些。为了让准确率和反馈率之间保持平衡,上述代码结合了这三种标注器。

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

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

标识化处理:机器所要理解的最小处理单位是单词(分词)。标识化处理,是将原生字符创分割成一系列有意义的分词。标识化就是将原生字符串分割成一系列有意义的分词。标识化处理的复杂性因具体NLP应用而异,目标语言本身的复杂性本身也会带来相关的变化。在英语中,可以通过正则表达式简单的单词来选取纯单词和数字,但在中文中会成为一个复杂的任务 from nltk.tokenize import word_tokenize from nltk.tokenize import regexp_tokenize,wordpunct_tokenize,blankline_tokenize s="Hi Everyone! hola gr8" print(s.split()) print(word_tokenize(s)) print(regexp_tokenize(s,pattern='\w+')) print(regexp_tokenize(s,pattern='\d+')) print(wordpunct_tokenize(s)) print(blankline_tokenize(s)) 结果: ['Hi', 'Everyone!', 'hola', 'gr8'] ['Hi', 'Everyone', '!', 'hola', 'gr8'] ['Hi', 'Everyone', 'hola', 'gr8'] ['8'] ['Hi', 'Everyone', '!', 'hola', 'gr8'] ['Hi Everyone! hola gr8'] 上面用到了各种标识器(tokenizer)Python字符串类型方法split():是一个最基本的标识器,使用空白符来执行单词的分割,split()本身也可以被配置成为一些较为复杂的标识化处理。word_tokensize()方法是一个通用的,强大的,面向对象的可面向对象所有类型预料库的标识化处理方法。regex_tokensize()是一个位用户需求设计的,自定义程度更高的表示器,如用可以基于正则表达式的标识器分割出相同的字符串,用/w分割出单词和数字用/d对数字进行提取词干提取:词干提取(stemming)是一个修枝剪叶的过程,通过一些基本的规则,可以得到所有的分词。词干提取是一种较为粗糙的过程,希望用它来取得相关的分词的各种变化,如eat这个词会有像eating,eaten,eats等变化。在某些情况下不需要区别这些,通常会用词干提取的方法将这些变化归结为相同的词根。对于简单的方法我们可以用词干提取,对于较为复杂的NLP问题,我们必须改用词形还原(lemmatization):下面是一个词干提取的例子: from nltk.stem import PorterStemmer from nltk.stem.lancaster import LancasterStemmer from nltk.stem.snowball import SnowballStemmer pst=PorterStemmer() lst=LancasterStemmer() print(lst.stem("eating")) print(pst.stem("shopping")) 结果: eat shop 一个拥有基本规则的词干提取器,在像移除-s/es、-ing或-ed这里事情上都可以达到70%的精确度。Poster1和lancaStemmer有更多的规则,精确度会更加高。当多种词干提取算法介入时,精确度和性能上会有差异。Snowball能处理荷兰语,英语,法语,德语,意大利语,葡萄牙语,罗马尼亚语和俄语等语言。词形还原:词形还原(lemmatization)涵盖了词根所有的文法和变化形式,还会利用上下文语境和词性来确定相关单词的变化,并运用不同的标准化规则,根据词性来获取相关的词根。 from nltk.stem import WordNetLemmatizer wlem=WordNetLemmatizer() print(wlem.lemmatize("ate")) 结果 ate WordNetLemmatizer使用了wordnet,会针对某个单词去搜索wordnet这个语义字典,还用到了变形分析,以便直切词根并搜索到特殊词形。停用词移除:停用词移除(Stop word removal)简单的移除预料库中在所有文档中可能出现的单词,通常是冠词和代词。 from nltk.corpus import stopwords stoplist=stopwords.words('english') #print(stoplist) text="This is just a test" out=cleanwordlist=[word for word in text.split() if word not in stoplist] print(out) 结果: ['This', 'test']

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

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

词性标注:词性(POS)常用的POS标记库Penn Treebank,PennTreeBank原本是一个NLP项目的名称,该项目主要是对相关语料进行标注,标注内容包括词性标注以及语法分析,其语料来自1989年的华尔街日报,包含2499篇文章。下面是Penn Treebank库编号 缩写 英文 中文1 CC Coordinating conjunction 并列连接词2 CD Cardinal number 基数3 DT Determiner 限定词4 EX Existential there 存在型there5 FW Foreign word 外文单词6 IN Preposition/subord, conjunction 介词/从属,连接词7 JJ Adjective 形容词8 JJR Adjective, comparative 形容词,比较级9 JJS Adjective, superlative 形容词,最高级10 LS List item marker 列表项标记11 MD Modal 情态动词12 NN Noun ,singular or mass 名词,可数或不可数13 NNS Noun, plural 名词,复数14 NNP Proper noun, singular 专有名词,单数15 NNPS Proper noun, plural 专有名词,复数16 PDT Predeterminer 前位限定词17 POS Possessive ending 所有格结束词18 PRP Personal pronoun 人称代名词19 PP$ Possessive pronoun 物主代词,所有格代名词20 RB Adverb 副词21 RBR Adverb, comparative 副词,比较级22 RBS Adverb, superlative 副词,最高级23 RP Particle 小品词24 SYM Symbol(mathematical or scientific) 符号(数学或科学)25 TO to To26 UH Interjection 感叹词27 VB Verb, base form 动词,基本形态28 VBD Verb, past tense 动词,过去式29 VBG Verb, gerund/present participle 动词,动名词/现在分词30 VBN Verb, past participle 动词,过去分词31 VBP Verb, non-3rd ps. sing. Present 动词,非第三人称单数现在式32 VBZ Verb, 3rd ps. sing. Present 动词,第三人称单数现在式33 WDT wh-determiner wh-限定词34 WP wh-pronoun wh-代词35 WP$ Possessive wh-pronoun 所有格wh-代词36 WRB wh-adverb wh-副词37 # Pound sign #符号38 $ Dollar sign 美元符号39 . Sentence-final punctuation 句点40 , Comma 逗号41 : Colon, semi-colon 冒号,分号42 ( Left bracket character 左括号43 ) Right bracket character 右括号44 “ Straight double quote 双引号45 ‘ Left open single quote 左单引号46 “ Left open double quote 左双引号47 ’ Right close single quote 右单引号48 ” Right close double quote 右双引号和中学时学的英语差不多。下面是一个简单的用POS语料库的例子: import nltk from nltk import word_tokenize s="I was watching TV" print(nltk.pos_tag(word_tokenize(s))) 结果: [('I', 'PRP'), ('was', 'VBD'), ('watching', 'VBG'), ('TV', 'NN')] 代码中先将文本进行表示化处理,再调用NLTK库中的pos_tag方法得到一组(词形,词性标签),可以看到很好地将一句话进行了标注。用POS语料库可以进行很多灵活的操作,如找出文本中所有的名词等: import nltk from nltk import word_tokenize s="I was watching TV" #print(nltk.pos_tag(word_tokenize(s))) tagged=nltk.pos_tag(word_tokenize(s)) allnoun=[word for word ,pos in tagged if pos in ['NN','NNP']] print (allnoun) 结果: ['TV'] 如果要找动词只需要改变pos的词性为 allnoun=[word for word ,pos in tagged if pos in ['VB','VBD','VBG ','VBN']]

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

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

Python基础:字典(dictionary)也是最常用到的一种数据结构。在其他语言中被称为关联数组/存储。字典是一种键值索引型的数据结构,其索引键可以是一种不可变的类型,例如字符串和数字常被用来充当索引键。Python的字典结构是哈希表实现之一。哈希表是一种操作起来非常容易的字典结构,其优势在于通过简短的代码就能建立起非常复杂的数据结构。例子用字典来获取文本中各单词出现的频率: mystring="Monty Python! And the holy Grail !\n" word_frep={} for tok in mystring.split(): if tok in word_frep: word_frep[tok]+=1 else: word_frep[tok]=1 print(word_frep) 结果: {'holy': 1, 'the': 1, 'Python!': 1, '!': 1, 'Grail': 1, 'And': 1, 'Monty': 1} NLTK入门:先介绍了一个简单的爬虫例子,爬取了Python官网主页上的文本信息: import urllib.request response=urllib.request.urlopen('http://python.org/') html=response.read() print(len(html)) 这里和书上的不同对于我用的python3.5,urllib2包已经不能用了,用urllib.request代替。结果; 48907 接下来做一次探索性数据分析(EDA),对于一段文本域而言,EDA可能包含多重含义,这里只会涉及一个简单的例子,即该文档的主体术语类型。文字的主体和出现的频率等。对于之前从Python主页爬的文字域,我们先清除其中的html标签,做法是先用正则表达式选取其中的标记,包括数字和字符,转换为一个列表;版本1: import urllib.request response=urllib.request.urlopen('http://python.org/') html=response.read() #print(len(html)) tokens=[tok for tok in html.split()] print("Total no of tokens:" +str (len(tokens))) print(tokens[0:100]) 结果; Total no of tokens:2932 [b'<!doctype', b'html>', b'<!--[if', b'lt', b'IE', b'7]>', b'<html', b'class="no-js', b'ie6', b'lt-ie7', b'lt-ie8', b'lt-ie9">', b'<![endif]-->', b'<!--[if', b'IE', b'7]>', b'<html', b'class="no-js', b'ie7', b'lt-ie8', b'lt-ie9">', b'<![endif]-->', b'<!--[if', b'IE', b'8]>', b'<html', b'class="no-js', b'ie8', b'lt-ie9">', b'<![endif]-->', b'<!--[if', b'gt', b'IE', b'8]><!--><html', b'class="no-js"', b'lang="en"', b'dir="ltr">', b'<!--<![endif]-->', b'<head>', b'<meta', b'charset="utf-8">', b'<meta', b'http-equiv="X-UA-Compatible"', b'content="IE=edge">', b'<link', b'rel="prefetch"', b'href="//ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">', b'<meta', b'name="application-name"', b'content="Python.org">', b'<meta', b'name="msapplication-tooltip"', b'content="The', b'official', b'home', b'of', b'the', b'Python', b'Programming', b'Language">', b'<meta', b'name="apple-mobile-web-app-title"', b'content="Python.org">', b'<meta', b'name="apple-mobile-web-app-capable"', b'content="yes">', b'<meta', b'name="apple-mobile-web-app-status-bar-style"', b'content="black">', b'<meta', b'name="viewport"', b'content="width=device-width,', b'initial-scale=1.0">', b'<meta', b'name="HandheldFriendly"', b'content="True">', b'<meta', b'name="format-detection"', b'content="telephone=no">', b'<meta', b'http-equiv="cleartype"', b'content="on">', b'<meta', b'http-equiv="imagetoolbar"', b'content="false">', b'<script', b'src="/static/js/libs/modernizr.js"></script>', b'<link', b'href="/static/stylesheets/style.css"', b'rel="stylesheet"', b'type="text/css"', b'title="default"', b'/>', b'<link', b'href="/static/stylesheets/mq.css"', b'rel="stylesheet"', b'type="text/css"', b'media="not', b'print,', b'braille,'] 版本2: import urllib.request import re response=urllib.request.urlopen('http://python.org/') html=response.read() html=html.decode('utf-8') tokens=re.split('\W+',html) print(len(tokens)) print(tokens[0:100]) 结果: 6221 ['', 'doctype', 'html', 'if', 'lt', 'IE', '7', 'html', 'class', 'no', 'js', 'ie6', 'lt', 'ie7', 'lt', 'ie8', 'lt', 'ie9', 'endif', 'if', 'IE', '7', 'html', 'class', 'no', 'js', 'ie7', 'lt', 'ie8', 'lt', 'ie9', 'endif', 'if', 'IE', '8', 'html', 'class', 'no', 'js', 'ie8', 'lt', 'ie9', 'endif', 'if', 'gt', 'IE', '8', 'html', 'class', 'no', 'js', 'lang', 'en', 'dir', 'ltr', 'endif', 'head', 'meta', 'charset', 'utf', '8', 'meta', 'http', 'equiv', 'X', 'UA', 'Compatible', 'content', 'IE', 'edge', 'link', 'rel', 'prefetch', 'href', 'ajax', 'googleapis', 'com', 'ajax', 'libs', 'jquery', '1', '8', '2', 'jquery', 'min', 'js', 'meta', 'name', 'application', 'name', 'content', 'Python', 'org', 'meta', 'name', 'msapplication', 'tooltip', 'content', 'The', 'official'] 注python3要用上 html=html.decode('utf-8') 否则会报错: cannot use a string pattern on a bytes-like object 接下来用NLTK的方式清理这些标签: import nltk import urllib from bs4 import BeautifulSoup response=urllib.request.urlopen('http://python.org/') html=response.read() html=html.decode('utf-8') soup=BeautifulSoup(html,'lxml') clean=soup.get_text() tokens=[tok for tok in clean.split()] print(tokens[:100]) 结果: ['Welcome', 'to', 'Python.org', '{', '"@context":', '"http://schema.org",', '"@type":', '"WebSite",', '"url":', '"https://www.python.org/",', '"potentialAction":', '{', '"@type":', '"SearchAction",', '"target":', '"https://www.python.org/search/?q={search_term_string}",', '"query-input":', '"required', 'name=search_term_string"', '}', '}', 'var', '_gaq', '=', '_gaq', '||', '[];', "_gaq.push(['_setAccount',", "'UA-39055973-1']);", "_gaq.push(['_trackPageview']);", '(function()', '{', 'var', 'ga', '=', "document.createElement('script');", 'ga.type', '=', "'text/javascript';", 'ga.async', '=', 'true;', 'ga.src', '=', "('https:'", '==', 'document.location.protocol', '?', "'https://ssl'", ':', "'http://www')", '+', "'.google-analytics.com/ga.js';", 'var', 's', '=', "document.getElementsByTagName('script')[0];", 's.parentNode.insertBefore(ga,', 's);', '})();', 'Notice:', 'While', 'Javascript', 'is', 'not', 'essential', 'for', 'this', 'website,', 'your', 'interaction', 'with', 'the', 'content', 'will', 'be', 'limited.', 'Please', 'turn', 'Javascript', 'on', 'for', 'the', 'full', 'experience.', 'Skip', 'to', 'content', '▼', 'Close', 'Python', 'PSF', 'Docs', 'PyPI', 'Jobs', 'Community', '▲', 'The', 'Python', 'Network'] 下面是用nltk进行词频的统计: import nltk import urllib from bs4 import BeautifulSoup response=urllib.request.urlopen('http://python.org/') html=response.read() html=html.decode('utf-8') soup=BeautifulSoup(html,'lxml') clean=soup.get_text() tokens=[tok for tok in clean.split()] #print(tokens[:100]) Freq_dist_nltk=nltk.FreqDist(tokens) print(Freq_dist_nltk) for k,v in Freq_dist_nltk.items(): print(str(k)+':'+str(v)) 结果: <FreqDist with 614 samples and 1117 outcomes> up:2 ==:1 now:3 document.getElementsByTagName('script')[0];:1 Best:1 "url"::1 -:1 core:1 [];:1 Statements:1 ga.src:1 s.parentNode.insertBefore(ga,:1 tkInter,:1 international:1 Trac,:1 Legal:1 Beginner’s:1 While:1 'Apple'),:1 here.:2 FOSDEM:2 Brochure:2 2018-01-09:1 Windows:3 programmers:1 Stories:3 Essays:2 _gaq.push(['_setAccount',:1 Interpretation:1 Up:1 Chat:1 discussed:1 Logo:2 window.jQuery:1 Search:1 List:2 comprehensions:1 processing:1 ?:1 b,:1 PyCon:2 'Banana'),:1 <:1 Easy:1 Diversity:3 1.:1 Contributing:1 Top:2 Learn:3 go.:1 User:4 even:1 Notice::1 for?:1 Arts:2 sure:1 programs:1 functions:2 it's:1 control:3 document.location.protocol:1 web2py:1 Government:2 Event:2 -,:1 tools:1 /:4 our:2 Industrial:1 A:2 Smaller:1 Scientific:3 compound:1 knows:1 About:2 Tru64,:1 rendering:1 Security:1 classic:1 Sign:3 have:1 Check:1 Solaris,:1 Copyright:1 quickly,:1 Javascript:2 =:14 Launch:1 Runs:1 987:1 Events:11 an:3 Whet:1 Getting:2 hire:1 Unicode):1 join:1 Mailing:2 Foundation:3 will:1 Roundup:1 Web:1 Hi,:1 learn.:1 Developer's:3 Submit:3 Django,:1 built-in:1 (PEPs)::1 GO:1 Types:1 I'm:2 lists.:1 Girls:1 alpha:1 used:2 Not:1 name):1 math:1 Started:3 Latest:1 Proposals:1 Python!"):1 21:1 to:17 55:1 expected;:1 syntax:2 Documentation:3 Latest::1 other:4 6,:1 }:2 programmers.:1 Engineering:2 limited.:1 Website:1 Talks:2 PSF:4 faster:1 can:3 lists:1 Numeric::1 3.6.4,:1 Implementations:2 377:1 Django:1 n::1 list:2 Data:1 pipeline.:1 —:2 Larger:1 relaunched:1 programming:4 PyGObject,:1 appetite:1 (1,:1 website,:1 Intuitive:1 structure:1 Python.:2 Linux,:1 ©2001-2018.:1 argument:1 IPython:1 Forums:2 What:1 a,:2 Kivy,:1 SciPy,:1 Pyramid,:1 for,:1 output:1 For:1 available.:2 own:1 one:1 **:1 "WebSite",:1 //:1 Meetup:1 You’d:1 Skip:1 (with:1 144:1 arithmetic:1 running:1 Conduct:2 turn:1 motion:1 Archive:4 allows:1 ['Banana',:1 is:',:1 Light:1 users:1 community-run:1 Contact:1 Compaq:1 speak:1 indentation:1 Issue:1 fruits:1 0:1 course.:1 operators:1 Upcoming:1 straightforward::1 re-code):1 Tracker:1 3.6.4:5 The:5 General:1 fruit:1 systems:1 Welcome:1 fib(n)::1 8:2 all:1 Become:1 versions!:1 release:1 job:1 you:1 '.google-analytics.com/ga.js';:1 daily.:1 languages:1 610:1 document.write('<script:1 manipulated:1 together:1 Quick:1 new:1 Powered:1 product):1 ≡:1 print(a,:1 of:17 Calculations:1 Tim:1 language,:1 ...:7 2018:2 Defined:1 input('What:1 essential:1 frames:1 2018-02-02:2 end=':1 Fibonacci:1 Flask,:1 use?:1 Lists:4 %s.':1 Please:1 functions.:2 'Lime']:1 development:1 Initiatives:1 standard:1 "potentialAction"::1 types:1 s:1 languages):1 [2,:1 enumerate:1 Donate:1 picture:1 Looking:1 "@type"::2 ():1 fib(1000):1 protect,:1 Enhancement:1 in:8 more:2 Jobs:2 +:1 Register:1 Menu:1 Code:2 Hello,:1 thousands:1 experienced:1 document.createElement('script');:1 2018-01-23:1 Practices:1 (and:1 future:1 grouping.:1 by:3 [(0,:1 News:11 0,:1 ['BANANA',:1 for…:1 true;:1 day.:1 library,:1 Flow:1 with:7 pick:1 number:2 Ansible,:1 4,:1 Software:6 (function():1 as:2 ga:1 testing.:1 OpenStack:1 easy:2 5.666666666666667:1 machines:1 last:1 find:1 Mac:2 environment:1 production:2 Source:2 print("Hello,:1 Special:2 3:8 'http://www'):1 '):1 fourth:2 keyword:1 docs.python.org:1 ▲:3 'LIME']:1 ga.type:1 per:1 System:1 3.:1 Fortenberry:1 Bug:1 Success:3 Awards:2 Input,:1 Development::3 Pandas,:1 3.7.0a4:1 print('Hi,:1 statements:1 arrays:1 name?:1 the:19 "http://schema.org",:1 twists,:1 parentheses:1 Platforms:2 "@context"::1 community:1 This:1 usual:1 growth:1 lets:1 are:5 Books:2 Alternative:2 ~800:1 Audio/Visual:2 effectively.:1 way:1 Back:2 89:1 Development:2 'Apple',:1 ILM:1 })();:1 arguments,:2 is::1 Our:1 some:1 Reset:1 "query-input"::1 *:2 Functions:1 four:1 "target"::1 Chelyabinsk:1 Rackspace:1 sliced:1 2:3 place:1 source:1 list(enumerate(fruits)):1 content:2 Privacy:1 def:1 License:2 key,:1 not:1 Simple:2 FAQ:2 very:1 PyPI:1 34:1 interaction:1 n:1 installers:1 Python:60 Conferences:2 float:1 numbers:1 Wiki:2 Guide:6 'Lime')]:1 Facebook:1 Buildbot,:1 ||:2 extensible:1 PyQt,:1 ::1 >>>:24 experience.:1 assignment:1 Community:7 Pythology:1 numbers::1 #:9 compositing:1 facilitate:1 quickly:1 series:1 IRC:3 advance:1 a+b:1 ga.async:1 arbitrary:1 Administration::1 var:3 2017-12-06:1 _gaq:2 for:11 Salt,:1 or:2 Core:1 PEP:2 Magic:1 Education:2 board:1 and:22 Legon:1 your:4 tens:1 language:2 mission:1 support:1 was:1 >_:1 Python,:1 while:2 Site:1 Applications:2 name?\n'):1 17:2 about:3 2017-12-19:2 that:5 version:1 Thousands:1 available:3 returns:1 jobs.python.org:1 position:1 'APPLE',:1 Interactive:1 _gaq.push(['_trackPageview']);:1 Groups:2 modeling,:1 promote,:1 X,:1 233:1 Merchandise:2 understands.:1 Non-English:2 Network:1 batch:1 3.5.5rc1:1 optional:1 Mentorship:1 product:5 floor:1 Expect:1 on:4 8]:1 Interest:2 %:1 which:1 'text/javascript';:1 print(loud_fruits):1 Socialize:1 0.5:1 Member:1 {:3 capable:1 One-Day:1 candidate:1 Whether:1 full:1 ('https:':1 Group:4 Close:1 "https://www.python.org/search/?q={search_term_string}",:1 In:2 developer,:1 fruits]:1 function:1 data:1 loud_fruits:1 Experienced:1 Downloads:2 Status:1 you're:2 expression:1 flow:2 python-dev:1 online.:1 indexed,:1 3::4 Google+:1 (known:1 is:16 src="/static/js/libs/jquery-1.8.2.min.js"><\/script>'):1 Python's:1 Use:1 its:1 3.4.8rc1:1 trying:1 clean:1 use:1 13:1 2018-02-03:3 Policy:1 3.6.4rc1:1 download:1 "SearchAction",:1 Beginner's:2 (2,:1 Conference::1 work:3 +,:1 planned:1 code:4 s);:1 range:1 this:2 overview.:1 loop:1 RSS:1 be:3 All:3 Bottle,:1 Business:2 tutorials:1 Twitter:1 runs:1 beginners:1 defining:2 GUI:1 Speed:1 OS:3 provide:1 learn:1 division:2 IRIX,:1 'https://ssl':1 [fruit.upper():1 if,:1 ▼:1 Start:1 diverse:1 Python.org:1 Shell:1 1:5 first:1 name:1 X:2 Download:1 releases:3 384:1 More:9 wxPython:1 Compound:1 Other:2 any:1 b:2 pipeline:1 along:1 related:1 integrate:1 PySide,:1 print('The:1 5:2 print():1 "required:1 Docs:6 &:3 Tornado,:1 Python!:1 name=search_term_string":1 "https://www.python.org/",:1 'UA-39055973-1']);:1 Get:1 simple:2 Help:3 guides,:1 Quotes:2 a:10 Index:2 mandatory:1 2.7.14:1 图表:

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

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

先来介绍一下相关的python基础:list:list是python中最基础的数据结构相对于其他语言中的数组:例子: >>>list=[1,2,3,4] >>>print (list) 结果:python是一种解释性语言,会在对其计算的同时检查其中的变量类型,我们在声明这些变量时无需对其进行初始化和类型声明,但在这里list中的包含一些整数对象,不能直接关联到print上,后者只能接受String类型的对象,所以要将列表元素转换为String类型。例子: >>>print('First element:'+str(list[0])) >>>print('Last element:'+str(list[-1])) >>>print('First three element:'+str(list[0:2])) >>>print(‘Last three element:’+str(list[-3:0])) 结果: First element:1 Last element:4 First element:1,2,3 Last element:2,3,4 常见的对字符串操作的函数:split():一个能基于默写分隔符来对于字符串进行切割的方法。如果你没有为其提供具体参数则默认空格为其分隔符。 >>>mystring="Monty Python! And the holy Grail !\n" >>>print (mystring.split()) 结果: ['Monty', 'Python!', 'And', 'the', 'holy', 'Grail', '!'] strip():一个可以从字符串中删除其尾随空白符(如‘n’,'nr')的方法例子: >>> print(mystring.strip()) Monty Python! And the holy Grail ! 通过rstrip()和lstrip()可以选择剥离字符串左边还是右边尾部的空白符upper()/lower():可以用来改变字符串中字母的大小写例子 >>> print(mystring.upper()) MONTY PYTHON! AND THE HOLY GRAIL ! replace()可以替换目标字符串中的某个子串例子: >>> print(mystring.replace('!',',')) Monty Python, And the holy Grail , 在NLP中正则表达式是另一个非常重要的技能。正则表达式(regular expression)能对字符串进行有效地匹配的模式,能从大量凌乱的文本数据中提取出有意义的信息。正则表达式一般有:(句号):用于匹配除换行字符外的任意单字符。w:用于匹配某一字符或者数字,相当于[a-z A-Z 0-9]W:用于匹配任意非单词性字符s:用于匹配任意单个空白字符,包括换行,返回制表等,相当于[nrt]S:用于匹配单个任意非空白字符。’t:用于匹配制表符。n:用于匹配换行符。r:用于匹配返回符。d:用于匹配十进制数字。^:用于匹配相关字符的开始位置。$:用于匹配先关字符串结尾位置。:用于低效特殊字符的特殊性。如要匹配$符号,则在前面加上.下面是一个使用字符串的子串搜索模块re来查找字符对象的例子。 import re mystring="Monty Python! And the holy Grail !\n" if re.search('Python' ,mystring): print("we found Python") else: print("No") 结果: We found Python findall()是一个用于对字符串进行全部模式查找的函数。他会按照给定模式对字符串进行查找,并列出其中所有匹配的对象: import re mystring="Monty Python! And the holy Grail !\n" print(re.findall("!",mystring)) 结果: ['!', '!'] findall()返回两个对象的列表。

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

主成分分析PCA学习笔记

主成分分析(principal components analysis,PCA)是一个简单的机器学习算法,主要思想是对高维数据进行降维处理,去除数据中的冗余信息和噪声。算法:输入样本:$D=\left \{ x_{1},x_{2},\cdots ,x_{m}\right \}$ 低纬空间的维数 过程:·1:对所有样本进行中心化:$x_i\leftarrow x_i-\frac{1}{m}\sum_{i=1}^{m}x_i$;2:计算所有样本的协方差矩阵:$XX^T$;3:对协方差矩阵$XX^T$做特征值分解;4:取最大的${d}'$个特征值做所对应的特征向量$w_1,w_2,\cdots ,w_{d'}$.输出:投影矩阵$W=(w_1,w_2,\cdots ,w_{d'})$PCA算法主要用在图像的压缩,图像的融合,人脸识别上: PCA 在python的sklearn包中给出了PCA的接口: from sklearn.decomposition import PCA import numpy as np X=np.array([[-1,-1],[-2,-1],[-3,-2],[1,1],[2,1],[3,2]]) #pca=PCA(n_components=2) pca=PCA(n_components='mle') pca.fit(X) print(pca.explained_variance_ratio_) 以自己造的数据集进行测试并测试程序提取了一个特征值 对二维数据进行降维 用PCA算法对testSet.txt数据集进行降维处理 import numpy as np import matplotlib.pyplot as plt def loadDataSet(filename, delim='\t'): fr = open(filename) StringArr = [line.strip().split(delim) for line in fr.readlines()] datArr = [map(float, line) for line in StringArr] return np.mat(datArr) def pca(dataMat, topNfeat=9999999): meanVals = np.mean(dataMat, axis=0) meanRemoved = dataMat - meanVals # remove mean covMat = np.cov(meanRemoved, rowvar=0) # 寻找方差最大的方向a,Var(a'X)=a'Cov(X)a方向误差最大 eigVals, eigVects = np.linalg.eig(np.mat(covMat)) eigValInd = np.argsort(eigVals) # sort, sort goes smallest to largest eigValInd = eigValInd[:-(topNfeat + 1):-1] # cut off unwanted dimensions redEigVects = eigVects[:, eigValInd] # reorganize eig vects largest to smallest lowDDataMat = meanRemoved * redEigVects # transform data into new dimensions reconMat = (lowDDataMat * redEigVects.T) + meanVals return lowDDataMat, reconMat dataMat = loadDataSet( 'testSet.txt') print(dataMat) lowDMat, recoMat = pca(dataMat, 1) print(u'特征值是:') print(lowDMat) print(u'特征向量是:') print(recoMat) fig = plt.figure() ax = fig.add_subplot(111) ax.scatter(np.array(dataMat[:, 0]),np.array(dataMat[:, 1]), marker='^', s=90) ax.scatter(np.array(recoMat[:, 0]), np.array(recoMat[:, 1]), marker='o', s=50, c='red') plt.show() def replaceNanWithMean(): datMat = loadDataSet('secom.data', ' ') numFeat = np.shape(datMat)[1] for i in range(numFeat): meanVal = np.mean(datMat[np.nonzero(~np.isnan(datMat[:, i].A))[0], i]) datMat[np.nonzero(np.isnan(datMat[:, i].A))[0], i] = meanVal return datMat dataMat = replaceNanWithMean() meanVals = np.mean(dataMat, axis=0) meanRemoved = dataMat - meanVals # remove mean covMat = np.cov(meanRemoved, rowvar=0) eigVals, eigVects = np.linalg.eig(np.mat(covMat)) eigValInd = np.argsort(eigVals) # sort, sort goes smallest to largest eigValInd = eigValInd[::-1] # reverse sortedEigVals = eigVals[eigValInd] total = sum(sortedEigVals) varPercentage = sortedEigVals / total * 100 # 计算主成分方差 fig = plt.figure() ax = fig.add_subplot(111) ax.plot(range(1, 21), varPercentage[:20], marker='^') plt.xlabel('Principal Component Number') plt.ylabel('Percentage of Variance') plt.show() 结果:蓝色三角形为原始数据,红色圆为数据的主方向,可以看到PCA算法很好地找到了数据的主方向 人脸识别: att_faces中含有40张脸,每张脸10张92*112像素灰度照片的数据集 这里以att_faces数据集为例: import os import operator from numpy import * import matplotlib.pyplot as plt import cv2 # define PCA def pca(data,k): data = float32(mat(data)) rows,cols = data.shape#取大小 data_mean = mean(data,0) data_mean_all = tile(data_mean,(rows,1)) Z = data - data_mean_all#中心化 T1 = Z*Z.T #计算样本的协方差 D,V = linalg.eig(T1) #特征值与特征向量 V1 = V[:,0:k]#取前k个特征向量 V1 = Z.T*V1 for i in range(k): #特征向量归一化 L = linalg.norm(V1[:,i]) V1[:,i] = V1[:,i]/L data_new = Z*V1 # 降维后的数据 return data_new,data_mean,V1#训练结果 #covert image to vector def img2vector(filename): img = cv2.imread(filename,0) #读取图片 rows,cols = img.shape imgVector = zeros((1,rows*cols)) #create a none vectore:to raise speed imgVector = reshape(img,(1,rows*cols)) #change img from 2D to 1D return imgVector #load dataSet def loadDataSet(k): #choose k(0-10) people as traintest for everyone ##step 1:Getting data set print ("--Getting data set---") #note to use '/' not '\' dataSetDir = 'att_faces/orl_faces' #读取文件夹 choose = random.permutation(10)+1 #随机排序1-10 (0-9)+1 train_face = zeros((40*k,112*92)) train_face_number = zeros(40*k) test_face = zeros((40*(10-k),112*92)) test_face_number = zeros(40*(10-k)) for i in range(40): #40 sample people people_num = i+1 for j in range(10): #everyone has 10 different face if j < k: filename = dataSetDir+'/s'+str(people_num)+'/'+str(choose[j])+'.pgm' img = img2vector(filename) train_face[i*k+j,:] = img train_face_number[i*k+j] = people_num else: filename = dataSetDir+'/s'+str(people_num)+'/'+str(choose[j])+'.pgm' img = img2vector(filename) test_face[i*(10-k)+(j-k),:] = img test_face_number[i*(10-k)+(j-k)] = people_num return train_face,train_face_number,test_face,test_face_number # calculate the accuracy of the test_face def facefind(): # Getting data set train_face,train_face_number,test_face,test_face_number = loadDataSet(4) # PCA training to train_face data_train_new,data_mean,V = pca(train_face,40) num_train = data_train_new.shape[0] num_test = test_face.shape[0] temp_face = test_face - tile(data_mean,(num_test,1)) data_test_new = temp_face*V #对测试集进行降维 data_test_new = array(data_test_new) # mat change to array data_train_new = array(data_train_new) true_num = 0 for i in range(num_test): testFace = data_test_new[i,:] diffMat = data_train_new - tile(testFace,(num_train,1)) sqDiffMat = diffMat**2 sqDistances = sqDiffMat.sum(axis=1) sortedDistIndicies = sqDistances.argsort() indexMin = sortedDistIndicies[0] if train_face_number[indexMin] == test_face_number[i]: true_num += 1 accuracy = float(true_num)/num_test print ('The classify accuracy is: %.2f%%'%(accuracy * 100)) def main(): facefind() if __name__=='__main__': main() 结果: 由于每次选择训练的图片是随机的,随后的准确率也是会变化的,当提高低维空间的维度时能提高准确率

资源下载

更多资源
Mario

Mario

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

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

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文件系统,支持十年生命周期更新。

用户登录
用户注册