Is it possible to use alias for keys in yaml with symfony/yaml? - symfony

I've been trying to read the following yaml file using symfony/yaml(v4.4.0) with cakephp3.
But, I get the following error.
Reference "aaa" does not exist in "path to yml" at line xx (near "*aaa:").
Symfony\Component\Yaml\Exception\ParseException
I would like to user the 'aaa' as a key later.
It doesn't work with "*aaa:" and works with "1:".
Basically, is it possible to use alias for keys in yaml file?
Here's the yaml file.
aaa: &aaa 1
bbb: &bbb 2
ccc: &ccc 3
*aaa: # <- this doesn't work and works with '1:'
- *bbb
- *ccc

For general spec-conforming YAML parsers
You need to write it with a space before :.
aaa: &aaa 1
bbb: &bbb 2
ccc: &ccc 3
*aaa :
- *bbb
- *ccc
YAML 1.2 allows : to be part of an anchor and therefore, the line will not be parsed as implicit key if : is written adjacent to the alias (since it becomes part of the alias then).
This has been discussed on the YAML core mailing list.
For Symfony
It seems Symfony parses *aaa: as alias *aaa with : as value indicator. While this is a spec violation, it shouldn't bother us since according to the mailing list, this is more like an oversight in the spec. However, Symfony fails to resolve the alias here, there's nothing much you can do about it but to file an issue for it.

Related

How to create a Anatomic Regions in Study Code Sequence

I'd like to edit a DICOM file with dcmodify to add an 'Anatomic Regions in Study Code Sequence' element (TAG: 0008,0063) but I'm unsure how to do this.
I can add the tag but what do I then add as its children? Is is it a list of (0018,0015) tags?
That should work:
$ dcmodify -i "(0008,0063)[0].(0018,0015)=FOOBAR" test.dcm
If you get something like:
E: modifying tag in file test.dcm: Invalid Path: Non-sequence tag found with rest path following
E: There was 1 error
This indicate that the attribute 0008,0063 is not declared in your dicom.dic file. Eg:
$ grep 0008,0063 /usr/share/dcmtk/dicom.dic
-> returns nothing
In that case simply update your dcmtk package.
ref:
DCMTK: dcmodify: Modify DICOM files

SonarQube: sonar.exclusions parameter cannot exclude a folder

I work on symfony project and I want to exclude some generated code from sonar analytics.
I want to exclude a folder named by this path: src/Application/Sonata.
I tried many possibilities with sonar exclusions but in vain:
sonar.exclusions=src/Application/Sonata/*
sonar.exclusions=src/Application/Sonata/**
sonar.exclusions=src/Application/Sonata/**/*
this is my sonar-project.properties file
# Required metadata
sonar.projectKey=project
sonar.projectName=project
sonar.projectVersion=0.1.3
# Description
sonar.projectDescription=project a base symphony 2
# Encoding of the source code
sonar.sourceEncoding=UTF-8
sonar.exclusions=src/Application/Sonata/**/* ,src/project/Resources/public/js/lib/**/*, src/project/Resources/public/js/jquery.validate.js
After many tests, i found the correct syntax of sonar.exclusions clause:
sonar.exclusions=src/Application/Sonata/**/*,src/Simuleo5BOBundle/Resources/public/js/lib/**/*,src/Simuleo5BOBundle/Resources/public/js/jquery.validate.js
Correctly setting exclusions from properties is difficult to get right, which is why it's not documented. Instead, you should use the UI to set your exclusions.

Error when inserting a UUID into YAML using "!!python/object"

For an automated test script, I would like to generate random UUID values at runtime, so I added some YAML that looks like this:
---
applicant:
idNumbers:
nationalId: !!python/object:uuid.uuid4
However, this generates an error when I try to yaml.load the value:
ConstructorError: expected a mapping node, but found scalar
in "<unicode string>", line 4, column 17:
nationalId: !!python/object:uuid.uuid4
^
How do I inject a UUID value via YAML tags?
I found the error message a bit intimidating at first, but after some thought, I was able to unpack it.
The parser is expecting a "mapping" node, not a scalar. So, what happens if I add a mapping?
>>> yaml.load('''---
... applicant:
... idNumbers:
... nationalId: !!python/object:uuid.uuid4 {}''')
{'applicant': {'idNumbers': {'nationalId': UUID('71e09d1d-e84e-4ea6-855d-be1a2e91b60a')}}}
Additional info: http://yaml.org/type/map.html

Why is "//*" the only xPath query that works when I'm parsing this XML in R using the XML-package?

I'm parsing a Swedish library catalogue using R and the XML-package. Using the library's API, I'm getting XML back from a url containing my query.
I'd like to use xPath queries to parse each record, but everything I do with xPath of the XML-package returns blank lists, everything except "//*". I'm no expert in either xml-parsing nor xPath, but I suspect that it has to do with the xml that my API returns to me.
This is a simple example of one single post in the catalogue:
library(XML)
example.url <- "http://libris.kb.se/sru/swepub?version=1.1&operation=searchRetrieve&query=mat:dok&maximumRecords=1&recordSchema=mods"
doc = xmlParse(example.url)
# Title
works <- xmlRoot(doc)[[4]][["record"]][["recordData"]][["mods"]][["titleInfo"]][["title"]][[1]]
doesntwork <- getNodeSet(doc, "//title")
# The only xPath that returns anything
onlythisworks <- getNodeSet(doc, "//*")
If this has something to do with namespaces (as these answers sugests), all I understan about it is that the API returns data that seems to have namespaces defined in the initial tag, and that I could use that, but this doesn't help me:
# Namespaces are confusing:
title <- getNodeSet(xmlRoot(doc), "//xsi:title", namespaces = c(xsi = "http://www.w3.org/2001/XMLSchema-instance"))
Here's (again) the example return data that I'm trying to parse.
You have to use the right namespace.
Try the following
doesntwork <- getNodeSet(doc, "//mods:title")
#[[1]]
#<title>Horizontal Slot Waveguides for Silicon Photonics Back-End Integration [Elektronisk resurs]</title>
#
#[[2]]
#<title>TRITA-ICT/MAP AVH, 2014:17 \
# </title>
#
#attr(,"class")
#[1] "XMLNodeSet"
BTW: I usually get the namespaces via
nsDefs=xmlNamespaceDefinitions(doc,simplify = TRUE,recursive=TRUE)
But this throws an error in your case. It complains that there are different URIs for the same name space prefix. According to
this site this does not seem to be good coding style.
Update as per OP's comment
I am myself not an xml expert, but here is my take: You can define default namespaces via <tag xmlns=URI>. Non default namespaces are of the form <tag xmlns:a=URI> with a being the respective namespace name.
The problem with your document is that there are two different default namespaces. The first being in <searchRetrieveResponse xmlns="http://www.loc.gov/zing/srw/" ... >. The second is in <mods xmlns="http://www.loc.gov/mods/v3" ... >. Also, you will find the second default namespace URI in the first tag as xmlns:mods="http://www.loc.gov/mods/v3" (where it is non-default). This seems rather messy. Now, the <title> tag is within the <mods> tag. I think that the default namespace defined in <mods> gets overridden by the non default namespace of searchRetrieveResponse (because they have the same URI). So although <mods> and all following tags (like <title>) seems to have default namespaces they actually have the xmlns:mods namespace. But this does not apply to the tag <numberOfRecords> (because it's outside of <mods>). You can access this node via
getNodeSet(doc, "//ns:numberOfRecords",
namespaces = c(ns="http://www.loc.gov/zing/srw/"))
Here you extract the default namespace defined in <searchRetrieveResponse> and give it a name (ns in our case). Then you can explicitly use the default namespace name in your xPath query.

Completing options of the form --<option>:<file> and --<option>:<possible values>

I'm trying to write a completion method for fsharpi (F# interactive), which has options like the following:
--use:<file> Use the given file on startup as initial input
--debug:{full|pdbonly} Specify debugging type: full, pdbonly. ('full' is the default and enables attaching a debugger to a running program).
--warn:<n> Set a warning level (0-5)
I'm guessing this has to be handled with $state similarly to sub-commands, but the documentation is monolithic and the language isn't very descriptive, so I've gotten nowhere with experimentation and by stitching together different examples.
A solution to this would also work for aspell, which uses an equals-sign instead of the colon e.g.
--conf=<str> main configuration file
This is one of the most common forms of completion, and it can be easily handled by _arguments. Note that literal colons in options can be quoted with a backslash. Here's the code example:
#compdef command
arguments=(
'--use\:-:initial input file:_files'
'--debug\:-:debugging type:(full pbonly)'
'--warn\:-:warning level:(0 1 2 3 4 5)'
)
_arguments -S $arguments[#]
Reference: _arguments in official documentation.

Resources