我正在尝试使用带有python的通用feedparser从Google新闻下载一组新闻(尝试进行一些自然语言处理).我对XML一无所知,我只是使用了如何使用feedparser的示例.问题是我在dict中找不到我从RSS提要获得的新闻内容只是标题.
我目前正在尝试使用的代码是:
import feedparser
url = 'http://news.google.com.br/news?pz=1&cf=all&ned=us&hl=en&output=rss'
# just some GNews feed - I'll use a specific search later
feed = feedparser.parse(url)
for post in feed.entries:
print post.title
print post.keys()
Run Code Online (Sandbox Code Playgroud)
我在这篇文章中得到的关键只是标题,摘要,日期等......没有内容.
这是谷歌新闻的一些问题还是我做错了什么?有办法吗?
是否有一些Haskell扩展能够创建比GADT更复杂的数据构造器?
假设我想创建一个有序列表的数据结构,并且有一个类似于(:)列表工作的数据构造函数,带有类型签名:
data MyOrdList a where
(>>>) :: (Ord a) -> a -> MyOrdList a -> MyOrdList a
Run Code Online (Sandbox Code Playgroud)
但我希望(>>>)有一个特定的行为,如下所示:
(>>>) :: (Ord a) => a -> [a] -> [a]
x >>> [] = [x]
x >>> xs = low ++ [x] ++ high
where low = filter (<x) xs
high = filter (>x) xs
Run Code Online (Sandbox Code Playgroud)
所以结构总是一个有序的结构.(我现在不知道如果这是一个很好的做法,我只是提供了我想要的行为类型的最简单的例子).
当然我可以使用一个函数(>>>),但是我将没有模式匹配和其他好处,我有它>>>是一个数据构造函数.
有没有办法做这样的事情?
所以我在不久前学会了Makefile,创建了一个模板Makefile,我所做的就是为我正在做的每个程序复制和更改同一个文件.我改了几次,但它仍然是一个非常粗糙的Makefile.我该怎样改进它?这是我当前版本的一个示例:
CC = g++
CFLAGS = -std=gnu++0x -m64 -O3 -Wall
IFLAGS = -I/usr/include/igraph
LFLAGS = -ligraph -lgsl -lgslcblas -lm
DFLAGS = -g -pg
# make all
all: run test
# make a fresh compilation from scratch
fresh: clean test
#makes the final executable binary
run: main.o foo1.o foo2.o
$(CC) $(CFLAGS) $(LFLAGS) $^ -o $@
#makes the test executable with debugging and profiling tags
test: test.o foo1.o foo2.o
$(CC) $(DFLAGS) $(CFLAGS) $(LFLAGS) $^ -o $@
#makes teste.o
teste.o: teste.cpp
$(CC) $(CFLAGS) …Run Code Online (Sandbox Code Playgroud) 我有一个程序,我必须在对每个组件进行一些计算后在屏幕上打印许多STL向量.所以我试着创建一个这样的函数:
template <typename a>
void printWith(vector<a> foo, a func(a)){
for_each(foo.begin(), foo.end(), [func](a x){cout << func(x) << " "; });
}
Run Code Online (Sandbox Code Playgroud)
然后像这样使用它:
int main(){
vector<int> foo(4,0);
printWith(foo, [](int x) {return x + 1;});
return 0;
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,我有一个关于我在printWith调用中放入的lambda表达式类型的编译错误:
g++ -std=gnu++0x -Wall -c vectest.cpp -o vectest.o
vectest.cpp: In function ‘int main()’:
vectest.cpp:16:41: error: no matching function for call to ‘printWith(std::vector<int>&, main()::<lambda(int)>)’
vectest.cpp:10:6: note: candidate is: void printWith()
make: *** [vectest.o] Error 1
Run Code Online (Sandbox Code Playgroud)
当然,如果我这样做:
int sumOne(int x) {return x+1;}
Run Code Online (Sandbox Code Playgroud)
然后printWith(foo, sumOne); …
我需要计算一些其值由以下无效的伪python代码给出的值:
def foo(a,b):
tmp = 0
for i in graph.nodes():
for j in graph.nodes():
tmp += c
if (i and j are neighbors):
tmp += a - c
elif (i and j are next-neighbors):
tmp += b - c
return tmp
Run Code Online (Sandbox Code Playgroud)
换句话说,给定所有节点对,foo = a *(E =边数)+ b *(EE =不是邻居但有一个公共邻居的对数)+ c *(N(N-1 )/ 2-EE-E)。
我试图考虑某种广度优先搜索,但我没有。
编辑:更多信息
我正在尝试使用pandoc从markdown文件中生成一个html幻灯片,其中包含一些乳胶.
该文件位于github.
如果我运行以下pandoc命令:
pandoc -s -t s5 --mathjax apresentacao.md -o index.html
Run Code Online (Sandbox Code Playgroud)
数学是由MathJax完美展示的,但我只得到一个包含所有幻灯片且没有幻灯片功能的网页.
如果我运行以下命令:
pandoc -s --self-contained -t s5 --mathjax apresentacao.md -o index.html
Run Code Online (Sandbox Code Playgroud)
我得到了一个非常好的演示文稿,但MathJax无法加载.生成的html文件(不完整)中包含二进制文件,用于加载的图像和javascript库.但它似乎无法正确合并MathJax.
你们有这个问题吗?有没有简单的方法来解决这个问题?
我正在使用以下pandoc版本:
$ pandoc --version
pandoc 1.11.1
Compiled with citeproc-hs 0.3.8, texmath 0.6.1.3, highlighting-kate 0.5.3.8.
Syntax highlighting is supported for the following languages:
actionscript, ada, apache, asn1, asp, awk, bash, bibtex, boo, c, changelog,
clojure, cmake, coffee, coldfusion, commonlisp, cpp, cs, css, curry, d,
diff, djangotemplate, doxygen, doxygenlua, dtd, eiffel, email, erlang,
fortran, fsharp, gnuassembler, …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习如何使用SBT以及我发现的以下简单示例未能找到scalatest的版本:
name := "DoingItWrong"
version := "0.0.1"
scalaVersion := "2.10.1"
libraryDependencies ++= Seq (
"org.scalatest" %% "scalatest" % "1.9.1" % "test"
)
Run Code Online (Sandbox Code Playgroud)
我在尝试sbt之前使用maven并且以下依赖项工作正常:
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.10</artifactId>
<version>1.9.1</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我得到以下输出试图运行SBT:
$ sbt package
[info] Loading global plugins from /home/rafael/.sbt/plugins
[info] Set current project to DoingItWrong (in build file:/home/rafael/Dev/DoingItWrong/)
[info] Updating {file:/home/rafael/Dev/DoingItWrong/}default-c52ace...
[info] Resolving org.scala-lang#scala-library;2.10.1 ...
[info] Resolving org.scalatest#scalatest_2.10.1;1.9.1 ...
[warn] module not found: org.scalatest#scalatest_2.10.1;1.9.1
[warn] ==== local: tried
[warn] /home/rafael/.ivy2/local/org.scalatest/scalatest_2.10.1/1.9.1/ivys/ivy.xml
[warn] ==== Sonatype snapshots: tried
[warn] http://oss.sonatype.org/content/repositories/snapshots/org/scalatest/scalatest_2.10.1/1.9.1/scalatest_2.10.1-1.9.1.pom
[warn] ==== public: tried …Run Code Online (Sandbox Code Playgroud) 我正在尝试用C++学习模板,我尝试的其中一件事就是编写一个地图函数,就像你通常在函数式语言中找到的那样.这个想法是这样的:
template <class X> X * myMap(X * func(X), X * array, int size)
{
X * temp;
for(int i = 0, i < size, i++) {temp[i] = (*func)(array[i]);}
return temp;
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试使用它时:
int test(int k) { return 2 * k;}
int main(void)
{
int k[5] = {1,2,3,4,5};
int *q = new int[5];
q = myMap(&test, k, 5);
for(int i=0; i<5; i++) {cout << q[i];}
delete [] q;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译时出现类型不匹配错误:
main.cpp:25: error: no matching function for call to …Run Code Online (Sandbox Code Playgroud) 我正在研究大熊猫对NLP和文本挖掘进行一些简单的计算,但我不太清楚如何去做.
假设我有以下数据框,关联人名和性别:
import pandas
people = {'name': ['John Doe', 'Mary Poppins', 'Jane Doe', 'John Cusack'], 'gender': ['M', 'F', 'F', 'M']}
df = pandas.DataFrame(people)
Run Code Online (Sandbox Code Playgroud)
对于我想要的所有行:
目标是将其用作数据集来训练分类器,该分类器可以确定给定名称是男性还是女性名称.
前两个操作非常简单:
def shingles(word, n = 3):
return [word[i:i + n] for i in range(len(word) - n + 1)]
df['firstname'] = df.name.map(lambda x : x.split()[0])
df['shingles'] = df.firstname.map(shingles)
Run Code Online (Sandbox Code Playgroud)
结果是:
> print df
gender name firstname shingles
0 M John Doe John ['joh', 'ohn']
1 F Mary Poppins Mary ['mar', 'ary']
2 F Jane …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习如何在Scala中执行monadic代码,但我错过了Haskell将类型约束为类型的能力,从而声明了函数的类型.
例如,我试着写类似replicateM的Control.Monad斯卡拉.如果不关心类型注释,这将是这样的:
def replicateM(n: Int)(x: M[A]): M[List[A]] = n match {
case 0 => map(x => List())
case _ => for {
head <- x
tail <- replicateM(n-1)(x)
} yield head: tail
}
Run Code Online (Sandbox Code Playgroud)
(我发现这可能不是更有效的实现,它只是一种简单的编写方式).
我绊倒的地方是:我如何在这里正确注释类型?M是什么类型的?如何将M仅限制为已flatMap定义的类型?我觉得我可以用特质做到这一点,但我不知道如何做.