!define YAML_DATA {
actor: User
usecases:
name: Browse Products
name: Purchase Product
}
!define ACTOR_NAME {%YAML_DATA.actor%}
!define UC_NAMES {%YAML_DATA.usecases.name%}
#startuml
actor %ACTOR_NAME%
%for uc in UC_NAMES%
usecase %uc%
%endfor%
%ACTOR_NAME% -> %uc%
#enduml
I tried replacing the "define" with a "function" but I'm lost because there's no documentation that covers this type of conversion.
Related
I am using Pandoc to generate a list of publications for my website. I'm using it solely to generate the html with the publications so that I can then paste the raw html in jekyll. This part works fine.
The complications arise when I tty to generate the html so that my name appears boldfaced in all entries. I'm trying to use this solution for that, which works when I apply it to a pure Latex document I am generating. However when I try to apply the same Pandoc, the html is generated without any boldface.
Here's my Pandoc file:
---
bibliography: /home/tomas/Dropbox/cv/makerefen4/selectedpubs.bib
nocite: '#'
linestretch: 1.5
fontsize: 12pt
header-includes: |
\usepackage[
backend=biber,
dashed=false,
style=authoryear-icomp,
natbib=true,
url=false,
doi=true,
eprint=false,
sorting=ydnt, %Year (Descending) Name Title
maxbibnames=99
]{biblatex}
\renewcommand{\mkbibnamegiven}[1]{%
\ifitemannotation{highlight}
{\textbf{#1}}
{#1}}
\renewcommand*{\mkbibnamefamily}[1]{%
\ifitemannotation{highlight}
{\textbf{#1}}
{#1}}
...
And here's the relevant part of my Makefile:
PANDOC_OPTIONS=--columns=80
PANDOC_HTML_OPTIONS=--filter=pandoc-citeproc --csl=els-modified.csl --biblatex
Again: this code generates the references fine. It just doesn't boldface anything as it is supposed to.
Any ideas?
EDIT
Bib entries look like this
#MISC{test,
AUTHOR = {Last1, First1 and Last2, First2 and Last3, First3},
AUTHOR+an = {2=highlight},
}
And versions are
- Biblatex 3.12
- Biber 2.12
You can use a lua filter to modify the AST. The following works for me to get the surname and initials (Smith, J.) highlighted in the references (see here). You can replace pandoc.Strong with pandoc.Underline or pandoc.Emph. Replace Smith and J. with your name/initials, save it as myname.lua and use something like:
pandoc --citeproc --bibliography=mybib.bib --csl.mycsl.csl --lua-filter=myname.lua -o refs.html refs.md
i.e. put the filter last.
local highlight_author_filter = {
Para = function(el)
if el.t == "Para" then
for k,_ in ipairs(el.content) do
if el.content[k].t == "Str" and el.content[k].text == "Smith,"
and el.content[k+1].t == "Space"
and el.content[k+2].t == "Str" and el.content[k+2].text:find("^J.") then
local _,e = el.content[k+2].text:find("^J.")
local rest = el.content[k+2].text:sub(e+1)
el.content[k] = pandoc.Strong { pandoc.Str("Smith, J.") }
el.content[k+1] = pandoc.Str(rest)
table.remove(el.content, k+2)
end
end
end
return el
end
}
function Div (div)
if 'refs' == div.identifier then
return pandoc.walk_block(div, highlight_author_filter)
end
return nil
end
Notes:
The above works if you use an author-date format csl. If you want to use a numeric format csl (e.g. ieee.csl or nature.csl) you will need to substitute Span for Para in the filter, i.e.:
Span = function(el)
if el.t == "Span" then
If you also want to use the multiple-bibliographies lua filter, it should go before the author highlight filter. And 'refs' should be 'refs_biblio1' or 'refs_biblio2' etc, depending on how you have defined them:
function Div (div)
if 'refs' or 'refs_biblio1’ or 'refs_biblio2’ == div.identifier then
For pdf output, you will also need to add -V csl-refs in the pandoc command if you use a numeric format csl.
The filter highlights Smith, J. if formated in this order by the csl. Some csl will use this format for the first author and then switch to J. Smith for the rest, so you will have to adjust the filter accordingly adding an extra if el.content[k].t == "Str”…etc. Converting to .json first will help to check the correct formatting in the AST.
When I try regexner it works as expected with the following settings and data;
props.setProperty("annotators", "tokenize, cleanxml, ssplit, pos, lemma, regexner");
Bachelor of Laws DEGREE
Bachelor of (Arts|Laws|Science|Engineering|Divinity) DEGREE
What I would like to do is that using TokenRegex. For example
Bachelor of Laws DEGREE
Bachelor of ([{tag:NNS}] [{tag:NNP}]) DEGREE
I read that to do this, I should use TokensregexNERAnnotator.
I tried to use it as follows, but it did not work.
Pipeline.addAnnotator(new TokensRegexNERAnnotator("expressions.txt", true));
Or I tried setting annotator in another way,
props.setProperty("annotators", "tokenize, cleanxml, ssplit, pos, lemma, tokenregexner");
props.setProperty("customAnnotatorClass.tokenregexner", "edu.stanford.nlp.pipeline.TokensRegexNERAnnotator");
I tried to different TokenRegex formats but either annotator could not find the expression or I got SyntaxException.
What is the proper way to use TokenRegex (query on tokens with tags) on NER data file ?
BTW I just see a comment in TokensRegexNERAnnotator.java file. Not sure if it is related pos tags does not work with RegexNerAnnotator.
if (entry.tokensRegex != null) {
// TODO: posTagPatterns...
pattern = TokenSequencePattern.compile(env, entry.tokensRegex);
}
First you need to make a TokensRegex rule file (sample_degree.rules). Here is an example:
ner = { type: "CLASS", value: "edu.stanford.nlp.ling.CoreAnnotations$NamedEntityTagAnnotation" }
{ pattern: (/Bachelor/ /of/ [{tag:NNP}]), action: Annotate($0, ner, "DEGREE") }
To explain the rule a bit, the pattern field is specifying what type of pattern to match. The action field is saying to annotate every token in the overall match (that is what $0 represents), annotate the ner field (note that we specified ner = ... in the rule file as well, and the third parameter is saying set the field to the String "DEGREE").
Then make this .props file (degree_example.props) for the command:
customAnnotatorClass.tokensregex = edu.stanford.nlp.pipeline.TokensRegexAnnotator
tokensregex.rules = sample_degree.rules
annotators = tokenize,ssplit,pos,lemma,ner,tokensregex
Then run this command:
java -Xmx8g edu.stanford.nlp.pipeline.StanfordCoreNLP -props degree_example.props -file sample-degree-sentence.txt -outputFormat text
You should see that the three tokens you wanted tagged as "DEGREE" will be tagged.
I think I will push a change to the code to make tokensregex link to the TokensRegexAnnotator so you won't have to specify it as a custom annotator.
But for now you need to add that line in the .props file.
This example should help in implementing this. Here are some more resources if you want to learn more:
http://nlp.stanford.edu/software/tokensregex.shtml#TokensRegexRules
http://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/ling/tokensregex/SequenceMatchRules.html
http://nlp.stanford.edu/nlp/javadoc/javanlp/edu/stanford/nlp/ling/tokensregex/types/Expressions.html
Please take a look at this picture:
I am trying to change "business object" text to it's instance name. I wonder if there is an easy way to do that without dealing with django's core code.
This is the model I'm using:
class Business(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=50)
description = models.TextField(blank=True)
industry = models.ManyToManyField(Industry)
class Meta:
verbose_name = 'Business'
verbose_name_plural = 'Businesses'
def __unicode__(self):
return "%s: %s" % (self.id, self.name)
Call the method __str__ instead of __unicode__. See https://docs.djangoproject.com/en/dev/intro/tutorial02/#playing-with-the-api and look for the info box called "__str__ or __unicode__?".
I had the same problem here. As Brenda J. Butler indicated (the link), it looks like if you are using Python 3.x you should define str() instead of unicode.
I have a working table:
#some javascript stuff
!define or { || }
#my stuff
!define headers { !-Authorization: Basic YWRtaW46cGFzc3dvcmQ=
Accept: application/json -! }
|Table:smartrics.rest.fitnesse.fixture.RestFixture|http://admin:password#localhost:5984/|
|setHeaders|${headers} |
|DELETE |/q-couch | | | jsonbody.ok ${or} jsonbody.error=="not_found" |
I now want to re-factor to make reusable component, and more readable test.
I tried this:
#what I hoped would be a reusable component.
|scenario|deletedb|name|
|Table:smartrics.rest.fitnesse.fixture.RestFixture|http://admin:password#localhost:5984/|
|setHeaders|${headers} |
|DELETE|/#dbName | | |jsonbody.ok ${or} jsonbody.error=="not_found" |
#A more readable test
|Script|
|deletedb|q-couch|
When I press test I get The instance scriptTableActor. does not exist on every line in the scenario, within the script.
Is what I am doing valid? What am I doing wrong?
Why the error
The scriptTableActor. error occurs since you do not give a reference to any fixture in your script table header. Snipped from ScriptTable guide:
The first row is simply the word "Script" followed by the name and constructor arguments of the fixture (known as the "actor") that will be used by the rest of the table. If there is no actor specified then the previous script table's actor on this test page will be used.
The RestFixture has a special fixture for script tables, so your first row should be defined as:
|Script|RestScriptFixture|http://admin:password#localhost:5984/|
Reusable RestFixture components
I have used a structure of scenarios (defined in a ScenarioLibrary) and building blocks that we include to get reusable components. This strategy could also be used with other fixtures than RestFixture.
In your case I would had defined following scenarios
!|Scenario|When a |http_verb |is sent to |service |with headers set to |headers|
|setHeaders|#headers|
|#http_verb|#service|
!|Scenario|the response should contain |element |equal to |value |or |second_element |equal to |second_value|
|check|js|(response.jsonbody.hasOwnProperty('#element') && response.jsonbody.#element.toString()==#value)!-||-!(response.jsonbody.hasOwnProperty('#second_element') && response.jsonbody.#second_element.toString()==#second_value)|true|
The second scenario is a bit hefty, so a explanation could be in order. Since I do not know if ok and error always are returned in your response, first it checks whether the element exists or not with response.jsonbody.hasOwnProperty('#element') and then it checks if it has the correct value with response.jsonbody.#element.toString()==#value). I have escaped the or operator || with !--!.
The building block wiki would look like following:
|Script|RestScriptFixture|${server}|
|When a |delete |is sent to |${service} |with headers set to |${headers}|
|the response should contain |${element} |equal to |${value} |or |${second_element} |equal to |${second_value}|
And the test wiki would be:
!define TEST_SYSTEM {slim}
!define server {http://admin:password#localhost:5984/}
!define headers { !-Authorization: Basic YWRtaW46cGFzc3dvcmQ=
Accept: application/json -! }
!define service {/q-couch/}
!define element {ok}
!define value {0}
!define second_element {error}
!define second_value {not_found}
!include PathTo.BuildingBlock
Some of the defines above, I probably would have put in the SetUp wiki.
I just started studying F# today and have begun working my way through the F# tutorials at http://www.tryfsharp.org/Learn/getting-started#data-structures
In the section above three snippets of code are provided to explain records and option types:
type Book =
{ Name: string;
AuthorName: string;
Rating: int option;
ISBN: string }
let unratedEdition =
{ Name = "Expert F#";
AuthorName = "Don Syme, Adam Granicz, Antonio Cisternino";
Rating = None;
ISBN = "1590598504" }
let printRating book =
match book.Rating with
| Some rating ->
printfn "I give this book %d star(s) out of 5!" rating
| None -> printfn "I didn't review this book"
I thought that I would be able to apply the printRating like so
printRating unratedEdition
but I get the following error
stdin(63,13): error FS0001: This expression was expected to have type
FSI_0005.Book
but here has type
FSI_0009.Book
I'm kinda stuck as to what I am doing wrong here. Any obvious reason that I am totally missing?
Glad that you figured out how to solve the problem and continue with the tutorials!
I think the automatic loading and evaluation of code snippets in Try F# is a bit confusing. The problem is that you first evaluate first snippet, which defined Book and unratedEdition. Then, you evaluate second snippet which re-defines Book - now, to F# interactive, this is a different type hiding the previous definition - together with printRating which is a function working on the new version of Book. When you call:
printRating unratedEdition
You are calling printRating which is a function that takes the new Book with a value of the old Book type as an argument (because unratedEdition is defined from an earlier interaction; it does not automatically get updated to the new Book type and the two types are not compatible).
You can understand this if you evaluate the following three snippets one by one:
// Snippet #1: Define first version of the 'Book' type and a value of
// this type named 'unratedEdition'
type Book =
{ Name: string; AuthorName: string; Rating: int option; ISBN: string }
let unratedEdition =
{ Name = "Expert F#"; Rating = None; ISBN = "1590598504";
AuthorName = "Don Syme, Adam Granicz, Antonio Cisternino"; }
// Snippet #2: Now, we re-define the 'Book' type (we could also add/remove
// fields to make it actually different, but even without that, this still
// defines a new type hiding the original one). We also define a function that
// operates on the new 'Book' type
type Book =
{ Name: string; AuthorName: string; Rating: int option; ISBN: string }
let printRating book =
match book.Rating with
| Some rating ->
printfn "I give this book %d star(s) out of 5!" rating
| None -> printfn "I didn't review this book"
// Snippet #3: This will not work, because we are calling function taking new
// 'Book' with old 'Book' as an argument. To make this work, you need to evaluate
// one (or the other) definition of Book, then evaluate 'unratedEdition' and then
// 'printRating' (so that the value and function operate on the same 'Book' type)
printRating unratedEdition
Note that the editor will complain that the above code is not valid, because it defines Book twice, so you can really only get this problem (easily) in Try F# which erases the content of the editor when loading a new snippet
Well I solved my own problem by running all the above code in one shot. i.e. Posting all 3 snippets plus my
printRating unratedEdition
into the REPL together and then hitting RUN. Previously I was using the "load and run" for each individual snippet. I guess it must be some issue with the REPL, or my limited understanding of how a REPL works.
EDIT**
I found myself running into this problem a number of times throughout the tutorial. So, if you have an error, and don't know why, try inserting all the relevant code into the REPL, THEN hit run. This has solved every issue I have run into so far.