How to recursively render YAML using Jinja2? - recursion

I have a YAML file with a structure that is not fixed (ex: the restaurant has attribute name and attribute food depending on the country, while the shop is only per country).
I would like to transform this YAML to get values for France only
ex:
myyaml:
restaurant:
name: "resto"
food:
italy: "pizza"
japan: "sushi"
france: "cheese"
shop:
italy: "Roma"
japan: "Tokyo"
France: "Paris"
for France I would have:
myyaml:
restaurant:
name: "resto"
food: "cheese"
shop: "Paris"
For this I would like to make a jinja2 template that would recursively parse the content of my YAML file and render it with the same structure but selecting only the values for "France".

Related

How to add multiple authors and multiple affiliations with Quarto and export it to MS Word?

I am looking for a way to produce something like this with Quarto in Rstudio. I would appreciate it if the output can be in docx format
Quarto extension authors-block does exactly what you want.
---
title: "Authors-block Example"
authors:
- name: Eric Scott
affiliations:
- ref: uf
corresponding: true
email: myemail#institute.edu
- name: Author Two
affiliations:
- ref: uf
- ref: eu
affiliations:
- id: uf
name: University of Florida, Gainesville, Florida 32611-0430 USA
- id: eu
name: Example University 123 Center Avenue, New York, New York 10027 USA
filters:
- authors-block
format:
docx: default
---

Google Maps and Firebase - What data type should I use for Storing markers by City?

When a user opens the map, I want to display all the markers in their city.
What data type should I use as the key for children of the Markers node?
I thought about using zip codes, but after googling, not all places around the world use zipcodes like in the USA.
I also thought about using a city name like Chicago, but what if there's another city with the same name?
Does anyone have any suggestions on what I should use?
If you want to display all markers from the Realtime Database that correspond to a certain city, I recommend you a schema that looks like this:
db
|
--- markers
|
--- USA (countryName)
|
--- Illinois (stateName)
|
--- Chicago (cityName)
|
--- $markerId
|
--- zipCode: "123456"
|
--- name: "markerOne"
|
--- dateCreated: 1674178220
|
--- lat: 31.12345
|
--- lng: -31.12345
Since I never heard about two cities that share the same within the same state, the above schema will do the trick. The zip code is not so important, because as you said, there are countries that do not have zip codes.
To query such a structure, the following DatabaseRefrence is required:
DatabaseReference db = FirebaseDatabase.getInstance().getReference();
DatabaseReference cityNameRef = db.child("markers")
.child(countryName)
.child(stateName)
.child(cityName);
cityNameRef.get().addOnCompleteListener(/* ... /*);
On the other hand, when using Firestore, to achieve the exact same result, the following schema will do the trick:
db
|
--- markers (collection)
|
--- $markerId (document)
|
--- countryName: "USA"
|
--- stateName: "Illinois"
|
--- cityName: "Chicago"
|
--- zipCode: "123456"
|
--- name: "markerOne"
|
--- dateCreated: 1674178220
|
--- lat: 31.12345
|
--- lng: -31.12345
And to query such a structure, the following query is required:
FirebaseFirestore db = FirebaseFirestore.getInstance();
CollectionReference markersRef = db.collection("markers");
Query queryByCountryAndStateAndCity = markersRef
.whereEqualTo("countryName", "USA")
.whereEqualTo("stateName", "Illinois")
.whereEqualTo("cityName", "Chicago");
queryByCountryAndStateAndCity.get().addOnCompleteListener(/* ... /*);

Unknown column in field list generating from fixture file

I've created a fixture file to test an element that I've created using Dna Design's Silverstripe Elemental package and Silverstripe seems to insist that the has_many relationship 'Elements' in ElementalArea doesn't exist.
SilverStripe\ORM\Connect\DatabaseException: Couldn't run query:
INSERT INTO "ElementalArea"
("Elements")
VALUES
(?)
Unknown column 'Elements' in 'field list'
I have the fixture file:
---
MyElement:
my-element:
...
ElementalArea:
elemental-area:
Elements: =>MyElement.my-element
I've tried running sake /dev/build "flush=all" and clearing /tmp/sivlerstripe-cache... with no luck
In Silverstripe 4 the Elemental module is namespaced. In our fixture yml file we must provide the full namespaced path for ElementalArea.
Also, on a has many relationship we can set the relationship on the has one side (the Element):
DNADesign\Elemental\Models\ElementalArea:
elemental-area:
Title: 'Area 1'
DNADesign\Elemental\Tests\Src\TestPage:
page1:
Title: 'Page 1'
URLSegment: 'test-page'
ElementalAreaID: =>DNADesign\Elemental\Models\ElementalArea.elemental-area
MyElement:
my-element:
Title: 'Element 1'
ParentID: =>DNADesign\Elemental\Models\ElementalArea.elemental-area

Change the length of ContextPre and ContextPost in Quanteda KWIC

Is there a way to increase the number of words appearing before and after the keyword in Quanteda kwic function?
I've tried by changing the numeric value in:
options(width = 200)
but it didn't work.
#KenBenoit
options(width) affects the number of text columns displayed by the R interpreter. You want the window argument to kwic():
> kwic(data_corpus_inaugural, "war against")
contextPre keyword contextPost
[1857-Buchanan, 2933:2934] advantage of the fortune of [ war against ] a sister republic, we
[1901-McKinley, 2284:2285] . We are not waging [ war against ] the inhabitants of the Philippine
[1901-McKinley, 2299:2300] portion of them are making [ war against ] the United States. By
[1901-McKinley, 2413:2414] used when those who make [ war against ] us shall make it no
[1933-Roosevelt, 1851:1852] Executive power to wage a [ war against ] the emergency, as great
> kwic(data_corpus_inaugural, "war against", window=7)
contextPre keyword contextPost
[1857-Buchanan, 2933:2934] to take advantage of the fortune of [ war against ] a sister republic, we purchased these
[1901-McKinley, 2284:2285] be deceived. We are not waging [ war against ] the inhabitants of the Philippine Islands.
[1901-McKinley, 2299:2300] . A portion of them are making [ war against ] the United States. By far the
[1901-McKinley, 2413:2414] needed or used when those who make [ war against ] us shall make it no more.
[1933-Roosevelt, 1851:1852] - broad Executive power to wage a [ war against ] the emergency, as great as the

RMarkdown: citecolor LaTeX option not being used

I am trying to create a JSS article using RMarkdown, but am not able to get options that typically get used with pdf_document, in particular, the citecolor option.
Here is an MWE, which is the standard JSS template that ships with the rticles package:
---
author:
- name: FirstName LastName
affiliation: University/Company
address: >
First line
Second line
email: name#company.com
url: http://rstudio.com
- name: Second Author
affiliation: Affiliation
title:
formatted: "A Capitalized Title: Something about a Package \\pkg{foo}"
# If you use tex in the formatted title, also supply version without
plain: "A Capitalized Title: Something about a Package foo"
# For running headers, if needed
short: "\\pkg{foo}: A Capitalized Title"
abstract: >
The abstract of the article.
keywords:
# at least one keyword must be supplied
formatted: [keywords, not capitalized, "\\proglang{Java}"]
plain: [keywords, not capitalized, Java]
preamble: >
\usepackage{amsmath}
output: rticles::jss_article
citecolor: blue
references:
- id: fenner2012a
title: One-click science marketing
author:
- family: Fenner
given: Martin
container-title: Nature Materials
volume: 11
URL: 'http://dx.doi.org/10.1038/nmat3283'
DOI: 10.1038/nmat3283
issue: 4
publisher: Nature Publishing Group
page: 261-263
type: article-journal
issued:
year: 2012
month: 3
---
# Introduction
[#fenner2012a]
# References
This does not highlight the reference to be blue. Do I have to adapt the entire template to change the one parameter?

Resources