我正在尝试在字符串中的单词之间添加HTML标签(通过html标签即HTML注释包装单词)。HTML标记应写入的位置由偏移量数组界定,例如:
//array(Start offset, End offset) in characters
//Note that annotation starts in the Start offset number and ends before the End offset number
$annotationCharactersPositions= array(
0=>array(0,3),
1=>array(2,6),
2=>array(8,10)
);
Run Code Online (Sandbox Code Playgroud)
因此,要使用以下HTML标记($ tag)注释以下HTML文本($ source)。包裹由$ annotationPositions数组定界的字符(不考虑源的HTML标记)。
$source="<div>This is</div> only a test for stackoverflow";
$tag="<span class='annotation n-$cont'>";
Run Code Online (Sandbox Code Playgroud)
结果应为以下内容(https://jsfiddle.net/cotg2pn1/):
charPos =--------------------------------- 01---------------------------- 2-------------------------------------------3------------------------------------------45-------67-----------------------------89-------10,11,12,13......
$output = "<div><span class='annotation n-1'>Th<span class='annotation n-2'>i</span></span><span class='annotation n-2'>s</span><span class='annotation n-2'> i</span>s</div> <span class='annotation n-3'>on</span>ly a test for stackoverflow"
Run Code Online (Sandbox Code Playgroud)
我如何编程下一个功能:
$cont=0;
$myAnnotationClass="placesOfTheWorld";
for ($annotationCharactersPositions as $position) {
$tag="<span class='annotation $myAnnotationClass'>"; …Run Code Online (Sandbox Code Playgroud) 我试着按照一些关于在rails中注释我的模型的在线教程.然而,似乎所有的教程都在讨论过时的注释版本或不正确的安装它是一团糟.
到目前为止,我尝试了以下内容
1)在Gemfile中添加了这个
gem 'annotate', '2.4.0'
Run Code Online (Sandbox Code Playgroud)
2)然后命令:
bundle install
Run Code Online (Sandbox Code Playgroud)
3)然后我看到安装了注释gem并显示在命令上
bundle show
Run Code Online (Sandbox Code Playgroud)
4)最后,为了注释我的模型,我使用了命令
bundle exec annotate --position before
Run Code Online (Sandbox Code Playgroud)
在这一点上,我期待我的模型被注释,但我得到的是以下错误消息:
/Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/railties/databases.rake:4:in `<top (required)>': undefined method `namespace' for main:Object (NoMethodError)
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/railtie.rb:33:in `load'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.2.1/lib/active_record/railtie.rb:33:in `block in <class:Railtie>'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/railtie.rb:184:in `instance_exec'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/railtie.rb:184:in `block in load_tasks'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/railtie.rb:184:in `each'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/railtie.rb:184:in `load_tasks'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/engine.rb:423:in `block in load_tasks'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/application/railties.rb:8:in `each'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/application/railties.rb:8:in `all'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/engine.rb:423:in `load_tasks'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/application.rb:145:in `load_tasks'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.2.1/lib/rails/railtie/configurable.rb:30:in `method_missing'
from Rakefile:7:in `<top (required)>'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/annotate-2.4.0/lib/annotate.rb:17:in `load'
from /Users/AM/.rvm/gems/ruby-1.9.2-p290/gems/annotate-2.4.0/lib/annotate.rb:17:in `load_tasks' …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个图例,该图例将采用自定义标签和颜色,与注释图中突出显示区域对应的alphas,而不是使用代码在图表中绘制的数据系列:
library(ggplot2)
data(economics)
p1 <- ggplot(data=economics, mapping=aes(x=date, y=unemploy)) +
geom_line(size=1) +
annotate("rect", xmin=as.Date('1970-01-01'), xmax=as.Date('1980-01-01'), ymin=-Inf, ymax=Inf, alpha=0.2, fill="red") +
annotate("rect", xmin=as.Date('1990-01-01'), xmax=as.Date('2000-01-01'), ymin=-Inf, ymax=Inf, alpha=0.2, fill="green") +
p1
Run Code Online (Sandbox Code Playgroud)
我想添加一个带有标签的传奇,上面写着"1970年代","20世纪90年代",相应的颜色为红色和绿色,其中alpha为0.2,对应于注释元素.有办法做到这一点吗?
我正在为不同的数据集制作对数图,并且需要包含最佳拟合线方程。我知道应该在图中的哪个位置放置方程,但是由于数据集具有非常不同的值,我想在注释中使用相对坐标。(否则,注释将针对每个数据集移动。)
我知道 matplotlib 的 annotate() 函数,我知道我可以使用 textcoords='axes fraction' 来启用相对坐标。当我按常规比例绘制数据时,它会起作用。但随后我将至少一个比例更改为记录,并且注释消失了。我没有收到错误消息。
这是我的代码:
plt.clf()
samplevalues = [100,1000,5000,10^4]
ax = plt.subplot(111)
ax.plot(samplevalues,samplevalues,'o',color='black')
ax.annotate('hi',(0.5,0.5), textcoords='axes fraction')
ax.set_xscale('log')
ax.set_yscale('log')
plt.show()
Run Code Online (Sandbox Code Playgroud)
如果我注释掉ax.set_xcale('log')and ax.set_ycale('log'),注释就会出现在图的中间(它应该在的地方)。否则,它不会出现。
在此先感谢您的帮助!
我正在尝试为Team Foundation Server 2010实现一个插件,该插件将创建有关团队项目中用户的报告.从概念上讲,为了正确实现此插件,我所需要的只是访问在Visual Studio中使用"注释"功能时获得的相同数据:我需要能够告诉谁是最后一个创建给定行的人代码
我已经在互联网上搜索了文档或代码示例,但我能找到的所有建议都是建议,例如使用TFS命令行工具或看似不完整的代码示例.
我不介意在客户端代码中做很多繁重的工作,但似乎没有一种明显的方法可以获取有关Changeset中代码内容的有用作者数据,也不会从合并详细信息返回.
我想使用 LateX 格式构建一个表达式,其中一些数字出现但以 LateX 表达式中的变量表示。
实际的目标是在axes.annotate()方法中使用这个,但是为了讨论,这里是一个原理代码:
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(-5, 5, 0.05)
fig = plt.plot(x, x**2)
plt.grid(True)
g = 3
plt.xlabel(r'$test {}$'.format(g))
plt.show()
Run Code Online (Sandbox Code Playgroud)
这没问题。的值g被传递给表达式。
但是,使用\frac{}{}和其他构造呢?将xlabel()上面的字符串替换为:
plt.xlabel(r'$test \frac{1}{}$'.format(g))
Run Code Online (Sandbox Code Playgroud)
给出:
IndexError: tuple index out of range
Run Code Online (Sandbox Code Playgroud)
我知道使用花括号会发生一些事情,并尝试了几种变体,但到目前为止没有任何效果。
我正在使用django 1.9
型号:
class Comment(models.Model):
title = models.CharField(max_length=250, null=False)
date = models.DateField(auto_now_add=True)
Run Code Online (Sandbox Code Playgroud)
由于'extra()'将在django中弃用,我试图弄清楚如何在不使用'额外'的情况下按年份计算评论组
这是带额外的代码:
Comment.objects.extra(select={'year': "EXTRACT(year FROM date)",
'month': "EXTRACT(month from date)"})\
.values('year', 'month').annotate(Count('pk'))
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助.
多语言网站,翻译存储在一个表的列中.需要将查询集传递给已经过滤过的翻译的模板.语言变量存储在会话中.
class Item(models.Model):
name = models.CharField(max_length=128)
description = models.ForeignKey(Localization)
class Localization(models.Model):
klingon = models.TextField(blank=True, null=True, verbose_name='klingon')
english = models.TextField(blank=True, null=True, verbose_name='english')
Run Code Online (Sandbox Code Playgroud)
想到用所需文本注释qs会很好,但是我没有找到如何使用字段值进行注释.就像是
item = Item.objects.all().annotate(text=description.klingon)
Run Code Online (Sandbox Code Playgroud)
另一种方法是使用模板过滤器
item.description|choose_lang:request
Run Code Online (Sandbox Code Playgroud)
但在模板之前排序qs似乎更整洁.
我试图在图中写一些文本以突出显示我的情节中的某些内容(相当于 matplotlib 中的“注释”)。任何的想法?谢谢
我不知道将数据添加到查询集会如此困难。就像,如果它不是直接来自数据库,那么它也可能不存在。即使我注释,新字段也是二等公民,并不总是可用。
为什么不序列化捕获我的注释字段?
模型
class Parc(models.Model):
# Regular Django fields corresponding to the attributes in the
# world borders shapefile.
prop_id = models.IntegerField(unique=True) # OBJECTID: Integer (10.0)
shp_id = models.IntegerField()
# GeoDjango-specific: a geometry field (MultiPolygonField)
mpoly = models.MultiPolygonField(srid=2277)
sale_price = models.DecimalField(max_digits=8, decimal_places=2, null=True)
floorplan_area = models.DecimalField(max_digits=8, decimal_places=2, null=True)
price_per_area = models.DecimalField(max_digits=8, decimal_places=2, null=True)
nbhd = models.CharField(max_length=200, null=True)
# Returns the string representation of the model.
def __str__(self): # __unicode__ on Python 2
return str(self.shp_id)
Run Code Online (Sandbox Code Playgroud)
询问:
parcels = Parc.objects\
.filter(prop_id__in=attrList)\
.order_by('prop_id') …Run Code Online (Sandbox Code Playgroud)