标签: annotate

使用注释插件+ JAXB在java'field'中插入自定义注释(在xsd - > java上)

使用案例:

想要将自定义注释插入到JAXB生成的java类中的字段中

问题:

使用Annotate插件+ JAXB [1],我能够成功插入自定义注释,但它们是在getter方法而不是字段中插入的.然而,Morphia(mongo DB)注释(我实际上想要插入)只能注释java字段[2].

我的测试xsd:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb" jaxb:version="2.1"
xmlns:annox="http://annox.dev.java.net" jaxb:extensionBindingPrefixes="annox">

<xsd:element name="hoo" type="External" />
<xsd:complexType name="External">
    <xsd:sequence>
        <xsd:element name="bar" type="xsd:string" />
        <xsd:element name="hoobar" type="xsd:string" />
    </xsd:sequence>
</xsd:complexType>
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)

我的测试绑定xjb:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
 version="2.1"
 xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"

  xmlns:annox="http://annox.dev.java.net" jaxb:extensionBindingPrefixes="annox">
  <jaxb:bindings schemaLocation="external.xsd" node="/xs:schema">

<jaxb:bindings node="xs:complexType[@name='External']/xs:sequence/xs:element[@name='bar']">
  <annox:annotate>
    <annox:annotate
      annox:class="java.lang.SuppressWarnings"
      impl="com.acme.foo.MyFieldBridge">
    </annox:annotate>
  </annox:annotate>
</jaxb:bindings>    
Run Code Online (Sandbox Code Playgroud)

我生成的java片段:

 @XmlElement(required = true)
protected String bar;
@XmlElement(required = true)
protected String hoobar;

/**
 * Gets the value of the bar property.
 * 
 * @return …
Run Code Online (Sandbox Code Playgroud)

java xml annotate jaxb jaxb2-basics

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

matplotlib的自定义箭头样式,pyplot.annotate

我正在使用matplotlib.pyplot.annotate在我的情节上绘制一个箭头,如下所示:

import matplotlib.pyplot as plt
plt.annotate("",(x,ybottom),(x,ytop),arrowprops=dict(arrowstyle="->"))
Run Code Online (Sandbox Code Playgroud)

我想使用箭头样式,一端是扁平线,另一端是箭头,所以组合样式"| - |" 和" - >"做一些我们称之为"| - >"的东西,但我无法弄清楚如何定义自己的风格.

我想我可能会尝试类似的东西

import matplotlib.patches as patches                                                                                                                                                                              
myarrow = patches.ArrowStyle("Fancy", head_length=0.4,head_width=0.2)
Run Code Online (Sandbox Code Playgroud)

(现在应该与" - >"相同;我可以稍后调整样式)但是如何告诉plt.annotate使用myarrow作为样式?plt.annotate没有arrowstyle属性,而arrowprops = dict(arrowstyle = myarrow)也不起作用.

我也尝试在arrowprops字典中定义它,例如

plt.annotate("",(x,ybottom),(x,ytop),arrowprops=dict(head_length=0.4,head_width=0.2))
Run Code Online (Sandbox Code Playgroud)

但这给了我关于没有属性'set_head_width'的错误.

那么,我如何定义自己的pyplot.annotate样式呢?

python customization plot annotate matplotlib

9
推荐指数
1
解决办法
6810
查看次数

是否有支持Annotate/Blame的java的Diff库?

我正在挖掘Google的免费(开源)Java差异库的结果,并且似乎有很多(其中一些甚至使用通用对象而不仅仅是使用字符串).

在我挖掘大量搜索结果而没有找到我正在搜索的内容之前,我先问一下:

这些差异库是否支持cvs annotate或svn blame等功能.我想要

  • 将电流String[]传递给函数
  • 继续将旧版本的String[]函数传递给函数,直到我用完所有版本,或者库告诉我没有原始行未被注释(最后一件事不是必须但非常有用,因为检索旧版本的String[]很贵,所以我想尽早停下来)
  • 调用一个函数,它给我一个ìnt[]告诉我当前版本的每一行,它在哪个版本上次更改或者它是否根本没有改变(即最后一个版本中的最后一个更改).

支持非Strings的对象很好,但没有必要.如果API不完全那样,我想我可以忍受它.

如果没有,任何人都可以建议一个可扩展的差异库,其中可以轻松添加该功能,最好是希望接收该功能作为贡献(并且在接受贡献之前不需要填充大量文书工作,例如GNU项目)?然后,我会自愿(至少尝试)将其添加到那里.

java diff annotate blame

8
推荐指数
1
解决办法
661
查看次数

如何在PHP中使用Imagick包装文本,以便将其绘制为多行文本?

PHP中的Imagick库允许您在图像上绘制文本.如何告诉Imagick根据一些有界文本框包装文本?

即,使单词显示为多行文本而不是单行.

php text annotate imagick

7
推荐指数
3
解决办法
1万
查看次数

如何使用imagick annotateImage中文文本?

我需要使用中文文本注释图像,我现在正在使用Imagick库.

中文文本的一个例子是

这是中文

使用的中文字体文件是这个

该文件最初名为华文黑体.ttf

它也可以在Mac OSX的/ Library/Font下找到

我已将其重命名为英语STHeiTi.ttf,可以更轻松地在php代码中调用该文件.

特别Imagick::annotateImage功能

我也在使用"如何在PHP中使用Imagick绘制包装文本?"的答案..

我使用它的原因是因为英语文本和应用程序的成功需要注释英文和中文,但不是同时注释.

问题是,当我使用中文文本运行annotateImage时,我得到的注释看起来像罍

代码包含在这里

php image annotate imagick

7
推荐指数
2
解决办法
3764
查看次数

使用matplotlib中的一个文本注释几个点

我想使用单个注释文本来注释几个带有几个箭头的数据点.我做了一个简单的解决方法:

ax = plt.gca()
ax.plot([1,2,3,4],[1,4,2,6])
an1 = ax.annotate('Test',
  xy=(2,4), xycoords='data',
  xytext=(30,-80), textcoords='offset points',
  arrowprops=dict(arrowstyle="-|>",
                  connectionstyle="arc3,rad=0.2",
                  fc="w"))
an2 = ax.annotate('Test',
  xy=(3,2), xycoords='data',
  xytext=(0,0), textcoords=an1,
  arrowprops=dict(arrowstyle="-|>",
                  connectionstyle="arc3,rad=0.2",
                  fc="w"))
plt.show()
Run Code Online (Sandbox Code Playgroud)

产生以下结果: 在此输入图像描述

但我真的不喜欢这个解决方案,因为它是......好吧,一个丑陋的黑客.

除此之外,它还会影响注释的外观(主要是使用半透明的bbox等).

所以,如果有人得到了实际的解决方案或者至少知道如何实现它,请分享.

python annotate matplotlib

7
推荐指数
1
解决办法
4461
查看次数

Django:如何在相关字段的相关字段上order_by

我正在使用annotate向对象添加属性,然后我可以将其用于order_by.但是,我想在关系的关系字段上进行注释.我知道我应该能够以某种方式使用双下划线符号到达现场,但我似乎无法绕过它.

以下是模型:

class Group(Taggable, Uploadable):
    name            = models.CharField(max_length=250, db_index=True)
    description     = models.TextField(max_length=5000, null=True,
                        blank=True, db_index=True)
    private         = models.BooleanField(default=False)
    members         = models.ManyToManyField(User, null=True,
                        related_name='members', through='GroupToUser')
    pending_members = models.ManyToManyField(User, null=True,
                        related_name='pending_members')
    admin           = models.ForeignKey(User, null=True)
    timestamp       = models.DateTimeField(auto_now_add=True)
    author          = models.ForeignKey(User, related_name='author')

class Discussion(Taggable, Uploadable):
    author      = models.ForeignKey(User)
    title       = models.CharField(max_length=250, db_index=True)
    description = models.TextField(max_length=5000, null=True,
                    blank=True, db_index=True)
    group       = models.ForeignKey(Group, null=True)
    timestamp   = models.DateTimeField(auto_now_add=True)

class DiscussionResponse(Uploadable):
    author     = models.ForeignKey(User)
    discussion = models.ForeignKey(Discussion)
    message    = models.TextField(max_length=5000)
    timestamp  = models.DateTimeField(auto_now_add=True)
Run Code Online (Sandbox Code Playgroud)

因此,讨论可以选择性地与组相关联,并且DiscussionResponses与讨论相关联.我想要做的是找到与组相关的任何讨论的最新DiscussionResponse(如果存在),并按此排序.

我已经达到了这个目的:

Group.objects.filter(some_filtering).distinct().annotate( …
Run Code Online (Sandbox Code Playgroud)

python django annotate sql-order-by

7
推荐指数
1
解决办法
2766
查看次数

用箭头标记matplotlib直方图bin

我有一个直方图,可以用下面的MWE复制:

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

pd.Series(np.random.normal(0, 100, 1000)).plot(kind='hist', bins=50)
Run Code Online (Sandbox Code Playgroud)

这创建了这样的情节:

示例直方图

那么我如何用给定整数的箭头标记bin?

例如,见下文,其中箭头标记包含整数300的bin.

带有整数bin的示例

编辑:我应该理想地添加箭头的y坐标应该由它标记的条的高度自动设置 - 如果可能的话!

python annotate matplotlib

7
推荐指数
1
解决办法
1952
查看次数

如何使用PHP用HTML注释字符串(即,如何通过偏移量将HTML标记插入字符串以保留有效的HTML)?

我正在尝试在字符串中的单词之间添加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)

html php string dom annotate

7
推荐指数
1
解决办法
319
查看次数

Django 注释意外限制 21

我想使用 django ORM 来完成计数分组,但limit 21每次都选择 sql 意外。不想要限制,为什么limit 21会出现,如何获取所有数据?

模型:

class Company(models.Model):
    company_no = models.CharField(primary_key=True, max_length=128)
    name = models.CharField(max_length=128)
    is_test = models.BooleanField(default=False)
    class Meta:
        db_table = 'company'

class User(models.Model):
    symbol = models.BigIntegerField(primary_key=True)
    is_test = models.BooleanField(default=False)

    class Meta:
        db_table = 'user'

class UserEmploy(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE, db_column='symbol', to_field='symbol', related_name='employ')
    company = models.ForeignKey(Company, on_delete=models.CASCADE, to_field='company_no', db_column='company_no', related_name='user_employ')
    class Meta:
        db_table = 'user_employ'
Run Code Online (Sandbox Code Playgroud)

我认为的 Django 代码:

   employ_qs_exclude_test = UserEmploy.objects\
        .exclude(user__is_test__in=utils.IS_TEST_MODE)\
        .values("company__name") \
        .annotate(employ_count=Count('user', distinct=True))\
        .order_by('company')
Run Code Online (Sandbox Code Playgroud)

sql日志:

SELECT `company`.`name`, COUNT(DISTINCT …
Run Code Online (Sandbox Code Playgroud)

django group-by annotate limit django-queryset

7
推荐指数
1
解决办法
1255
查看次数