我试图在D3中调整一个简单的散点图程序来接受CSV文件.当我使用文件中的数据时,它工作得很好,但是当我尝试加载CSV文件时,它根本不起作用.我有什么简单的遗失吗?CSV文件"datatest.csv"的内容与代码中的数据集相同.我已经检查过浏览器正在加载数据,似乎一切都在那里.我想我只是错过了一步.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>D3 Demo: Linear scales</title>
<script type="text/javascript" src="../d3/d3.v3.js"></script>
<style type="text/css">
/* No style rules here yet */
</style>
</head>
<body>
<script type="text/javascript">
//Width and height
var w = 900;
var h = 500;
var padding = 20;
var dataset = [];
// var dataset = [
// [5, 20], [480, 90], [250, 50], [100, 33], [330, 95],
// [410, 12], [475, 44], [25, 67], [85, 21], [220, 88],
// [600, 150]
// ]; …Run Code Online (Sandbox Code Playgroud) 我有一个文本文件,每次出现"get"这个词时我需要@在它后插入一个符号.
在Python中如何使用正则表达式在特定单词后添加字符?现在我正在逐字解析这行,我不完全理解正则表达式编写代码.
我在一个非常大的列表中遇到了速度问题.我有一个包含很多错误和非常奇怪的文字的文件.我正在尝试使用difflib在我拥有的650,000个单词的字典文件中找到最接近的匹配项.下面这种方法效果很好,但非常慢,我想知道是否有更好的方法来解决这个问题.这是代码:
from difflib import SequenceMatcher
headWordList = [ #This is a list of 650,000 words]
openFile = open("sentences.txt","r")
for line in openFile:
sentenceList.append[line]
percentage = 0
count = 0
for y in sentenceList:
if y not in headwordList:
for x in headwordList:
m = SequenceMatcher(None, y.lower(), x)
if m.ratio() > percentage:
percentage = m.ratio()
word = x
if percentage > 0.86:
sentenceList[count] = word
count=count+1
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助,软件工程甚至不是我的强项.非常感激.
有没有办法使用nltk.NaiveBayesClassifier.classify获得个体概率?我想看看分类的可能性,试图建立一个置信度量表.显然,对于二元分类器,决策将是一个或另一个,但有没有办法看到决策是如何做出的内部工作?或者,我只需要编写自己的分类器吗?
谢谢
我正在尝试在eclipse中实现coreNLP情绪分析器.得到错误:
Unable to resolve "edu/stanford/nlp/models/lexparser/englishPCFG.ser.gz"
Run Code Online (Sandbox Code Playgroud)
作为类路径,文件名或URL.我使用maven安装了所有NLP文件,因此我不确定它为什么要寻找其他东西.这是我收到错误的代码.
import java.util.Properties;
import edu.stanford.nlp.ling.CoreAnnotations;
import edu.stanford.nlp.neural.rnn.RNNCoreAnnotations;
import edu.stanford.nlp.pipeline.Annotation;
import edu.stanford.nlp.pipeline.StanfordCoreNLP;
import edu.stanford.nlp.sentiment.SentimentCoreAnnotations;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.util.CoreMap;
public class StanfordSentiment {
StanfordCoreNLP pipeline;
public StanfordSentiment(){
Properties props = new Properties();
props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
pipeline = new StanfordCoreNLP(props);
}
public float calculateSentiment (String text) {
float mainSentiment = 0;
int longest = 0;
Annotation annotation = pipeline.process(text);
for (CoreMap sentence : annotation.get(CoreAnnotations.SentencesAnnotation.class)) {
Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class);
int sentiment = RNNCoreAnnotations.getPredictedClass(tree) - 2;
String …Run Code Online (Sandbox Code Playgroud) 我对RE不太熟悉,但我试图迭代一个列表并用来re.sub从变量中保存的大块文本中取出多个项目first_word.
我首先使用re.sub删除标签,这很好,但我接下来想要删除exclusionList变量中的所有字符串,我不知道如何做到这一点.
感谢您的帮助,以下是引发异常的代码.
exclusionList = ['+','of','<ET>f.','to','the','<L>L.</L>']
for a in range(0, len(exclusionList)):
first_word = re.sub(exclusionList[a], '',first_word)
Run Code Online (Sandbox Code Playgroud)
例外情况:
first_word = re.sub(exclusionList[a], '',first_word)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 151, in sub
return _compile(pattern, flags).sub(repl, string, count)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 245, in _compile
raise error, v # invalid expression error: nothing to repeat
Run Code Online (Sandbox Code Playgroud) 我认为最好的方法是使用正则表达式,但我不知道该怎么做.我试图解析一个字符串,并在字母和标点之间放置一个空格.我想把标点符号放在一起.举个例子,如果我有字符串
"是!!!"
我想结束
"是","!!!".
如果我有字符串
!N00bs,
我想结束
"!!!","N00bs"
这可能吗?做这个的最好方式是什么?现在我正在解析每个字母,这是一种愚蠢的方式.
谢谢您的帮助.
有没有办法将变量传递choice()给列表的函数.我有一堆列表,我想从一个列表中随机选择,然后使用返回的字符串从具有该字符串名称的列表中进行选择.
A = ['1','2','3']
print choice (A) - this gets me a random choice from the list
Run Code Online (Sandbox Code Playgroud)
但我想将选项存储为变量并使用它来调用另一个列表
A = ['1','2','3']
1 = ['A','B','C']
Var1 = choice (A)
print choice (Var1) *** this is my problem, how do I pass a variable to the choice function
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助!
我正在寻找"." 在字典中并尝试删除键/值对,如果我找到它
if "." in dict.values():
#delete key, value pair from the dictionary
Run Code Online (Sandbox Code Playgroud)
我确信这很简单,但我似乎无法找到解释.谢谢你的帮助.
我有一句话:" 这不是一个好句子 ",我试图_在单词not之后插入一个下划线().我现在使用的代码是
i = "this is not a good sentence"
i = re.sub(r'(not)', r'\1_', i)
Run Code Online (Sandbox Code Playgroud)
这个输出:" 这不是一个好句子 "
我希望它输出:" 这不是一个好句子 "
如何在没有句子移位的情况下进行分组?我希望" 不 "和" a "由下划线连接,但现在有一个空格.
使用下面的代码,我将已经标记和标记化的rss feed分块。“ print subtree.leaves()”输出:
[('Prime','NNP'),('Minister','NNP'),('Stephen','NNP'),('Harper','NNP')] [('US','NNP' ),(“总统”,“ NNP”),(“巴拉克”,“ NNP”),(“奥巴马”,“ NNP”)] [['what \','NNP')] [['Keystone', '(NNP'),('XL','NNP')] [('CBC','NNP'),('新闻','NNP')]
这看起来像一个python列表,但我不知道如何直接访问它或对其进行迭代。我认为这是一个子树输出。
我希望能够将此子树转换为可以操纵的列表。是否有捷径可寻?这是我第一次在python中遇到树木,我迷路了。我要结束此列表:
docs = [“总理史蒂芬·哈珀”,“美国总统巴拉克·奥巴马”,“内容”,“基斯通XL”,“加拿大广播公司新闻”]
有没有简单的方法可以做到这一点?
谢谢,一如既往的帮助!
grammar = r""" Proper: {<NNP>+} """
cp = nltk.RegexpParser(grammar)
result = cp.parse(posDocuments)
nounPhraseDocs.append(result)
for subtree in result.subtrees(filter=lambda t: t.node == 'Proper'):
# print the noun phrase as a list of part-of-speech tagged words
print subtree.leaves()
print" "
Run Code Online (Sandbox Code Playgroud) 我是编程新手.我希望能够为我的列表中的两个条目运行此程序,但是不能理解编程以使其正确.这个网站的成员已帮助我做到这一点,该程序适用于一组标签.我想让它运行所以我可以一次搜索多个作者.输出结果是它只收集"Shakes"的所有信息.然后停下来.我只是不知道如何格式化循环以使其正确.
这是我正在使用的代码:
authorList = ['Shakes.','Scott']
with open('/Users/Adam/Desktop/Poetrylist.txt','w') as output_file:
with open('/Users/Adam/Desktop/2e.txt','r') as open_file:
the_whole_file = open_file.read()
start_position = 0
for x in authorList:
while True:
start_position = the_whole_file.find('<A>'+x+'</A>', start_position)
if start_position < 0:
break
end_position = the_whole_file.find('</W>', start_position)
output_file.write(the_whole_file[start_position:end_position+4])
output_file.write("\n")
start_position = end_position + 4
Run Code Online (Sandbox Code Playgroud)
我确信这是一个非常简单的问题,但我正在尝试自学python并且它的进展非常缓慢.
python ×9
list ×4
regex ×4
text ×3
nltk ×2
chunks ×1
csv ×1
d3.js ×1
dependencies ×1
dictionary ×1
html ×1
java ×1
javascript ×1
key-value ×1
loops ×1
memory ×1
nlp ×1
optimization ×1
parsing ×1
random ×1
stanford-nlp ×1
string ×1
tree ×1
variables ×1