我试图通过使用内置方法在文本中找到与NLTK的搭配.
现在我有以下示例文本(test和foo相互跟随,但两者之间有一个句子边框):
content_part = """test. foo 0 test. foo 1 test.
foo 2 test. foo 3 test. foo 4 test. foo 5"""
Run Code Online (Sandbox Code Playgroud)
标记化的结果collocations()如下:
print nltk.word_tokenize(content_part)
# ['test.', 'foo', 'my', 'test.', 'foo', '1', 'test.',
# 'foo', '2', 'test.', 'foo', '3', 'test.', 'foo', '4', 'test.', 'foo', '5']
print nltk.Text(nltk.word_tokenize(content_part)).collocations()
# test. foo
Run Code Online (Sandbox Code Playgroud)
如何防止NLTK:
所以在这个例子中它根本不应该打印任何搭配,但我想你可以设想更复杂的文本,其中句子中也有搭配.
我可以猜测我需要使用Punkt句子分段器,但后来我不知道如何将它们再次组合起来找到与nltk的搭配(collocation()似乎比仅仅计算东西更强大).
我的任何项目都没有问题.就在最近,当我在arch linux中运行pacman-update(更新到5.4)时,我的许多项目都不再可以运行了.
有趣的是,只有在文件系统上创建会话文件时才会出现问题.我的意思是,只要/ tmp/sess*不存在,我就可以第一次调用该网站.
当我想第二次调用它并且/ tmp/sess*已经写入时,我收到以下错误(包括stacktrace,Zend Framework).
Zend_Controller_Exception: session has already been started by session.auto-start or session_start()#0 /srv/http/bahasa/library/Zend/Session/Namespace.php(143): Zend_Session::start(true)
#1 /srv/http/bahasa/library/Zend/Auth/Storage/Session.php(87): Zend_Session_Namespace->__construct('Zend_Auth')
#2 /srv/http/bahasa/library/Zend/Auth.php(91): Zend_Auth_Storage_Session->__construct()
#3 /srv/http/bahasa/library/Zend/Auth.php(141): Zend_Auth->getStorage()
#4 /srv/http/bahasa/library/Skoch/Controller/Plugin/Navigation.php(59): Zend_Auth->hasIdentity()
#5 /srv/http/bahasa/library/Zend/Controller/Plugin/Broker.php(287): Skoch_Controller_Plugin_Navigation->dispatchLoopStartup(Object(Zend_Controller_Request_Http))
#6 /srv/http/bahasa/library/Zend/Controller/Front.php(928): Zend_Controller_Plugin_Broker->dispatchLoopStartup(Object(Zend_Controller_Request_Http))
#7 /srv/http/bahasa/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#8 /srv/http/bahasa/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#9 /srv/http/bahasa/public/index.php(30): Zend_Application->run()
#10 {main} in /srv/http/bahasa/library/Zend/Controller/Plugin/Broker.php on line 312
Run Code Online (Sandbox Code Playgroud)
当然我已经在stackoverflow上检查了这个问题的其他答案,但是:
同样如上所述,一旦我从PHP 5.3更新到PHP 5.4,就会发生奇怪的事情.问题是,降级似乎不起作用(然后mysql库以某种方式被破坏).
正如已经提到的,对我来说最奇怪的是,它只发生在/ tmp中创建会话文件时.当/ tmp没有会话文件时,一切都很完美.
是的,这不仅是我自己的项目受到影响,而且我正在为另一家公司(在他们的服务器和本地PC上运行像魅力)工作,所以这也与我自己的代码中的问题相矛盾(同样的事情发生在两个Zend Framework项目中).
当然,我的项目也在PHP 5.2.12的在线网站空间中运行.
我猜之前的PHP通知也可能很有趣: …
我在这里遇到一个非常基本的问题,即使它必须存在,我也无法找到解决方案.
我有以下代码:
public class Foo {
public static void main(String[] args) {
String foo;
if (foo != null) {
System.out.println("foo");
} else {
System.out.println("foo2");
}
}
}
Run Code Online (Sandbox Code Playgroud)
它给了我
''变量可能尚未初始化''
.为什么我必须明确地指定null,并且默认情况下并非所有变量都用null初始化?
我目前正在尝试创建一个文本选择脚本,以便人们可以标记文本,然后将其插入到表单中.
因此,我想显示一个带有"发送到表单"链接的弹出窗口,但是我在创建一个带有qtip的工具提示时遇到了问题(我在我的网站上的任何地方都使用它)从我的脚本中找出文本是否已被标记(如果我的脚本无法复制任何内容,则不会有链接).
我正在使用此脚本进行选择检测:http://mark.koli.ch/2009/09/use-javascript-and-jquery-to-get-user-selected-text.html
如果当前有一个a alert,则稍后将调用qtip:
Kolich.Selector.mouseup = function(){
var st = Kolich.Selector.getSelected();
if(st!=''){
alert("You selected:\n"+st); // here will be showQTipAtMouseButtonFixed()
}
}
Run Code Online (Sandbox Code Playgroud)
现在问题似乎是整个qtip都集中在悬停上.我当然可以围绕.qtip()调用包装一个函数,但这并没有真正解决问题.然后工具提示将附加到我的功能,并且只有当我悬停它所连接的元素时仍然显示.
这将是包装函数的qtip
function showQTipAtMouseButtonFixed() {
$('#content').qtip({
content: 'Hello!',
position: {
target: 'mouse',
adjust: { mouse: false }
},
hide: {
fixed: true
},
style: {
tip: true,
classes: 'ui-tooltip-red'
}
});
}
Run Code Online (Sandbox Code Playgroud)
使用this而不是"#content"(我在相关帖子中看到)也不起作用.
但是我希望它在背景中始终处于活动状态,并在Kolich.Selector说"现在你被显示了!"时显示.
我还show: 'click' 通过Google找到了一个提示,但这也不是解决方案.它只适用于您真正假设点击的情况,但在我的情况下,它更像是双击或鼠标移动或键盘.
这可能与qtip或我必须display从头开始使用CSS 吗?
java是否包括一个本机类,该类允许最多数量的元素,并且如果我再输入一个元素,它将自动删除旧的元素(例如,基于自然排序)?
如果没有,我当然可以自己写,但是我只是想问一下。