小编Art*_*hur的帖子

Boost Log 2.0:日志中的空严重级别

我正在使用Boost-Log 2.0,它与版本1存在一些差异,我很难输出"Severity"属性.

我正在使用"Boost.Format-style"格式化程序

"%TimeStamp% [%Uptime%] (%LineID%) <%Severity%>: %Message%"
Run Code Online (Sandbox Code Playgroud)

TimeStamp,LineIDMessagecommon_attributes.Uptime是我添加的属性attrs::timer().我认为Severity在使用时会自动添加severity_logger,但显然不是,这是我的问题.我得到空的严重性,例如:

2013-Apr-06 19:21:52.408974 [00:00:00.001337] (3) <>: A warning severity message
Run Code Online (Sandbox Code Playgroud)

注意空<>.我试图添加严重性,register_simple_formatter_factory但后来我得到编译器错误:

error: no matching function for call to ‘register_simple_formatter_factory(const char [9])’
Run Code Online (Sandbox Code Playgroud)

而且我不明白为什么.

这是我的代码:

#include <iostream>


#include <boost/log/common.hpp>
#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>
#include <boost/log/sinks/text_file_backend.hpp>
#include <boost/log/sinks/sync_frontend.hpp>
#include <boost/log/sinks/text_ostream_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/formatter_parser.hpp>
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/severity_feature.hpp>
#include <boost/log/sources/record_ostream.hpp>

#include <boost/log/attributes.hpp> …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-log

25
推荐指数
2
解决办法
1万
查看次数

MongoDB是一个社交网站(在Ruby on Rails中开发)的好主意吗?

我的项目(在Ruby on Rails 3中)是开发一个具有以下功能的"社交网络"网站:

  • 用户可以是朋友.这是相互的友谊; 不像Twitter那样不对称.
  • 用户可以发布链接以共享它们.用户的朋友可以看到该用户共享的内容.
  • 朋友可以对这些共享链接发表评论.

所以基本上我们有用户,链接和评论,以及所有连接的.社交网络中一个有趣的事情是User表与自身有多种多样的关系.

我想我可以用SQL和RoR来处理这种复杂程度.

我的问题是:将MongoDB(或CouchDB)用于此类网站是否是一个好主意?

说实话,我认为答案是否定的.MongoDB似乎不适合多对多关系.我想不出一个好的MongoDB方式来实现友谊关系.我已经读过Diaspora从MongoDB开始,但后来切换回经典SQL.

但网上的一些文章为MongoDB的社交网络辩护,最重要的是我想做出明智的决定,不要错过MongoDB的一个非常酷的方面来改变我的生活.

另外,我听说过图形数据库,这可能很棒,但它们对我来说似乎太年轻了,我不知道它们如何适合RoR(并没有提到heroku).

那么,我错过了什么吗?

谢谢,

阿瑟斯

sql ruby-on-rails social-networking mongodb nosql

21
推荐指数
2
解决办法
1万
查看次数

Python"float"和PostgreSQL"双精度"的浮点数

Python的"浮点"类型和PostgreSQL的"双精度"类型是否基于相同的C实现?这可能不是真正的潜在问题,但无论如何,这是我在两个环境中尝试操作小数字时得到的结果:

在Python(2.7.2 GCC 4.2.1,如果相关):

>>> float('1e-310')
1e-310
Run Code Online (Sandbox Code Playgroud)

在PostgreSQL(9.1.1)上:

postgres# select 1e-310::double precision;
ERROR:  "0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001" is out of range for type double precision
Run Code Online (Sandbox Code Playgroud)

据我所知,Python float类型"处理"1e-310而PostgreSQL双精度类型则不然.双方的PythonPostgreSQL的文档上,分别是"浮动"和"双精度"类型,请参阅IEEE 754标准,这是应该的"大多数平台"实现的(我在OS X狮子10.7.3).

谁能解释一下这里发生了什么?并给我一个解决方案,我想要"减少"Python精度,以便我可以通过Django FloatField在我的数据库中插入浮点数.(完整的用例是我正在从文件中读取数据然后插入它们).

Python中的一些(可能有趣的)附加信息:

>>> sys.float_info
sys.float_info(max=1.7976931348623157e+308, max_exp=1024, max_10_exp=308, min=2.2250738585072014e-308, min_exp=-1021, min_10_exp=-307, dig=15, mant_dig=53, epsilon=2.220446049250313e-16, radix=2, rounds=1)
>>> 1e-320.__sizeof__()
24
Run Code Online (Sandbox Code Playgroud)

我真的没有得到第二个.

python django postgresql floating-point

6
推荐指数
1
解决办法
3081
查看次数

begin() 如何知道要返回哪种返回类型(常量或非常量)?

这完美地工作:

list<int> l;
list<int>::const_iterator it;
it = l.begin();
list<int>::iterator it2;
it2 = l.begin();
Run Code Online (Sandbox Code Playgroud)

我不明白的是如何list“知道”它必须返回iterator begin()版本或版本const_iterator begin() const

我正在尝试为我的容器(trie)实现迭代器,但我遇到了这个问题。难道 C++ 不应该通过返回类型来处理微分(除非使用奇怪的技巧)?

这是我得到的一些代码和编译器错误:

MyTrie<T>是一个可以包含任何类型的模板化树。我有一个Trie<int>::iter非常量迭代器和一个Trie<int>::const_iter常量迭代器。iter begin()const_iter begin() const在 Trie 类中声明(和定义)。

Trie<int> t;
Trie<int>::const_iter it;
it = t.begin();
Run Code Online (Sandbox Code Playgroud)

错误 :

../test/trie.cpp:181: error: no match for 'operator=' in 'it = Trie<T>::begin() [with T = int]()'
[..path..]/Trie.h:230: note: candidates are: Trie<int>::const_trie_iterator& Trie<int>::const_trie_iterator::operator=(const Trie<int>::const_trie_iterator&)
Run Code Online (Sandbox Code Playgroud)

所以,我相信begin不使用非常量版本。

我考虑operator=(const Trie<T>::const_trie_iterator&)为非常量迭代器创建一个方法,但我在 …

c++ iterator stl std

6
推荐指数
1
解决办法
2768
查看次数

C++情感分析库

我正在寻找一个可以在我自己的应用程序中使用的C++情绪分析库.将人类写成文本作为论据并返回其情绪信息的东西(积极的,消极的,中立的,愤怒的,快乐的......).有任何想法吗?

几点评论:

  • 我不是在寻找一个带有"正义"NLP工具的库(如文本标记化,PoS标记等),但实际上它可以进行情感分析/意见挖掘/情绪分析.当然,带有情感分析工具的NLP库非常棒.
  • 非常简单的东西就可以了(例如只返回+ 1/-1/0)
  • 我不关心它可能使用哪种基础技术(字典,贝叶斯东西,SVM,基于规则......)
  • 仅限C++!

我知道它可能不存在就像那样,但是嘿.

c++ nlp sentiment-analysis

5
推荐指数
1
解决办法
3464
查看次数

C++累加器库,能够删除旧样本

在Boost.Accumulator中,您可以将样本添加到累加器,然后从中提取统计量.例如:

acc(1.)
acc(2.)
acc(3.)
cout << mean; // 2
Run Code Online (Sandbox Code Playgroud)

图书馆有很多更复杂的统计量,例如skewness,kurtosisp_square_cumulative_distribution.

我想做的是这样的事情:

acc(1.)
acc(2.)
acc(3.)
std::cout << mean(acc); // 2
acc.pop() // withdraw the first value (1.)
std::cout << mean(acc); // 2.5
Run Code Online (Sandbox Code Playgroud)

pop()将以FIFO(先进先出)方式工作.我想要做的是在滑动时间窗口内以在线(增量)方式计算我的数据的统计数据.

累加器必须在内部保留所有值.

我可以自己做,但我总是首先检查现有的库,并且可能有一些算法,我不知道在数据传入或传出时巧妙地计算数量.

c++ boost machine-learning accumulator

5
推荐指数
2
解决办法
2346
查看次数