我正在使用一个名为Guess Language的python库:http://pypi.python.org/pypi/guess-language/0.1
"justwords"是一个带有unicode文本的字符串.我把它粘在包里,但它总是返回英文,即使网页是日文的.有谁知道为什么?我没有正确编码吗?
§ç©ºéå
¶ä»æ¡å°±æ²æéç¨®å¾ é¤ï¼æä»¥ä¾é裡ç¶ç
éäºï¼åæ¤ç°å¢æ°£æ°¹³åèµ·ä¾åªè½ç®âå¾å¥½âé常好âåå ¶æ¯è¦é»é¤ï¼é¨ä¾¿é»çé»ã飲æãä¸ææ²»çåä¸å 便å®ï¼æ¯æ´è¥ç äºï¼æ³æ³é裡以å°é»ãæ¯è§ä¾èªªä¹è©²æpremiumï¼åªæ±é¤é»å¥½å就好äºã<br /><br />é¦åç¾ï¼æä»¥å°±é»å宿´ç æ£è¦åä¸ä¸å
ä¸ç å¥é¤å§ï¼å
justwords = justwords.encode('utf-8')
true_lang = str(guess_language.guessLanguage(justwords))
print true_lang
Run Code Online (Sandbox Code Playgroud)
编辑:谢谢你的帮助.这是问题的更新.
我试图"猜测"这个语言:http://feeds.feedburner.com/nchild
基本上,在Python中,我得到了htmlSource.然后,我使用BeautifulSoup剥离标签.然后,我将它传递给图书馆以获取语言.如果我不进行编码('utf-8'),则会出现ASCII错误.所以,这是必须的.
soup = BeautifulStoneSoup(htmlSource)
justwords = ''.join(soup.findAll(text=True))
justwords = justwords.encode('utf-8')
true_lang = str(guess_language.guessLanguage(justwords))
Run Code Online (Sandbox Code Playgroud) 我有一组结构,定义如下:
typedef struct
{
int index;
int array[10];
}
Item;
typedef struct
{
Item A;
Item B;
Item C;
}
Collection;
Run Code Online (Sandbox Code Playgroud)
我想声明一个类型的变量,Collection如下所示:
Collection collection =
{
{ 1, 0 }, /* item A */
{ 2, 0 }, /* item B */
{ 3, 0 } /* item C */
};
Run Code Online (Sandbox Code Playgroud)
这会将三个index变量设置为1,2和3,同时将所有三个array[]变量初始化为零吗?
它似乎正在我的编译器上工作,但我想知道这是否是标准行为.
我编写了以下程序,用于使用增强条件变量来交替增加和加倍计数器(增量优先).任何人都能告诉我这是否正确使用了增强条件变量.它工作正常.我不明白在wait函数调用中使用lock.condition.wait(lock)是什么意思?例如,在此程序中增量和乘法使用两个范围锁是什么.我该如何避免它们?
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/bind.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/condition_variable.hpp>
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;
int counter=0;
boost::mutex m1,m2;
bool incremented=false,multiplied=false;
boost::condition_variable c1,c2;
void Increment()
{
{
boost::mutex::scoped_lock lk(m1);
counter++;
incremented = true;
c1.notify_one();
while(!multiplied)
c2.wait(lk);
multiplied=false;
}
}
void Multiply()
{
{
boost::mutex::scoped_lock lk(m2);
while(!incremented)
c1.wait(lk);
incremented = false;
counter = counter*2 ;
multiplied = true;
c2.notify_one();
}
}
void IncrementNtimes(int n){
for(int i=0;i<n;i++){
Increment();
}
}
void MultiplyNtimes(int n){
for(int i=0;i<n;i++){
Multiply();
} …Run Code Online (Sandbox Code Playgroud) 我添加了用户在我的谷歌地图上添加新点的功能.我的代码:
GEvent.addListener(map, "click", function(overlay,point) {
if (point) {
var myHtml = '<div id="addpoint"><form id="formadd" name="formadd_point" enctype="multipart/form-data" method="post" action="pointadd.php"><table><tr><td>Place:</td><td>' + point + '</td></tr><tr><td>Name:</td><td><input name="name" type="text" size="32" maxlength="200" /></td></tr><tr><td>Photo (jpg,png:2Mb):</td><td><input type="file" name="image" size="20" accept="image/png,image/jpeg" /></td></tr><tr><td></td><td><input name="pcoord" type="hidden" value="'+point+'" /><input type="hidden" name="MAX_FILE_SIZE" value="2000000" /><input name="subpoint" type="submit" value="Add" /></td></tr></table></form></div>';
map.openInfoWindowHtml(point, myHtml);
$('#formadd').ajaxForm({ beforeSubmit: validate, target:'#addpoint' });
}
});
Run Code Online (Sandbox Code Playgroud)
它应该是没有重新加载的AJAX帖子.但它不起作用!我不知道为什么.也许有一些冲突jquery.js和google api?如何在不重页的情况下提交表单?
谁能告诉我为什么我会收到错误以及如何修复它?
QGridLayout* mainLayout = new QGridLayout;
QGridLayout *leftLayout = new QGridLayout;
QGridLayout *rightLayout = new QGridLayout;
mainLayout->addLayout(leftLayout);
mainLayout->addLayout(rightLayout);
setLayout(mainLayout);
Run Code Online (Sandbox Code Playgroud)
错误我得到:'错误:没有匹配函数调用'QGridLayout :: addLayout(QGridLayout*&)'
谢谢你的帮助.
目前有一个数据库格式如下:
id(唯一ID)
网址:http://domain.com/page.html
网址来自同一个域和来自不同的域.
这也需要在一个查询中完成,这样我可以在向最终用户显示数据时使用限制等内容.
数据
1, http://domain.com/about.html
2, http://domain.com/index.html
3, http://anotherdomain.com/index.html
4, http://anotherdomain.com/contact.html
Run Code Online (Sandbox Code Playgroud)
预期输出
(我只想返回每个组的第一个url(首先是对数据进行排序的命令,此示例为"id ASC"),其中组由共享根域的URL组成.)
1, http://domain.com/about.html
3, http://anotherdomain.com/index.html
Run Code Online (Sandbox Code Playgroud) 我正在尝试学习C++,现在我正在编写一个需要输出整数对列表的程序.
处理这个问题的最佳方法是什么?我在学校的linux电脑上没有可用的升级库,所以我不相信我可以使用boost :: tuple.
有什么建议?
我正在尝试使用ASIHTTPRequest执行异步请求,但在请求完成时收到通知时会遇到一些问题.
-(void)doDownload{
NSURL *url = [NSURL URLWithString:@"http://www.someurl.com/?"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"someValue" forKey:@"someField"];
[request setRequestMethod:@"POST"];
[request setDelegate:self];
[request setDidFinishSelector:@selector(requestFinished)];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
}
Run Code Online (Sandbox Code Playgroud)
requestFinished永远不会被调用.我在ASIHTTPRequest.m,-handleStreamCompleted中得到一个异常:
if (fileError) {
[self failWithError:fileError];
} else {
[self requestFinished]; <----- this call fails
}
Run Code Online (Sandbox Code Playgroud)
有线索吗?
是否有一个firefox插件,让我忽略一段代码?
如果我关闭js,页面加载但我无法访问管理员,因为这需要js.
我想留下js,但我的浏览器只是忽略了几行代码.
可能?
谢谢!
假设我们有:
public class FooBase
{
public void Write(byte value)
{
//something
}
public void Write(int value)
{
//something
}
}
public class Foo : FooBase
{
public void Write(decimal value)
{
//something
}
}
Run Code Online (Sandbox Code Playgroud)
比这个:
var writer = new Foo();
writer.Write(5); //calls Write(decimal) !!
writer.Write((byte)6); //calls Write(decimal) !!
Run Code Online (Sandbox Code Playgroud)
将调用Write(十进制)重载.为什么?我怎样才能调用Write(int)或Write(byte)?