Version 1 (modified by 9 years ago) ( diff ) | ,
---|
Deze tagcontrole wordt beschouwd als de opvolger van tagchecker.cfg
en gebruikt veel van de implementatie van MapCSS voor stylesheets]. De officiële extensie voor bestanden is *.validator.mapcss
.
Het hoofdticket voor implementatie was #9414.
Meer complexe validatietesten, die niet gedaan kunnen worden met deze syntaxis worden gerealiseerd als Java-testen.
Syntaxis
selector { /* exact één van */ throwError: "message"; throwWarning: "message"; throwOther: "message"; /* willekeurig aantal van */ fixAdd: "key=val"; fixRemove: "key"; fixChangeKey: "old=>new"; suggestAlternative: "elke tekst (bijv., alternatieve sleutel)"; /* asserties voor eenheidstesten */ assertMatch: "node/way/relation key1=value1 keyN=valueN"; assertNoMatch: "node/way/relation key1=value1 keyN=valueN"; }
Nog enkele details:
- De syntaxis van selectors wordt gespecificeerd in Selectors
- Als alternatief voor tekenreeksen aan de rechterkant van deze expressies, worden expressies geëvalueerd (zie lijst+syntaxis])
- het meest nuttige van alles is tr() om die tekenreeks vertaald te krijgen
- Als tenminste één
fixAdd
/fixRemove
/fixChangeKey
wordt gespecificeerd, worden die wijzigingen uitgevoerd voor objecten die overeenkomen met deze test wanneer u drukt op de knop Repareren in het dialoogvenster Validatie. - Als
suggestAlternative
aanwezig is/zijn, worden die alternatieven weergegeven tezamen met het testbericht assertMatch
enassertNoMatch
: U kunt hier voorbeelden opgeven die wel (assertMatch) of niet (assertNoMatch) zouden moeten overeenkomen met de gebruikte selector. Zo is dit een test als de selector juist werkt voor het opgegeven voorbeeld. Normaal gesproken is dit alleen nuttig voor meer complexe selectors en minder voor eenvoudige selectors van sleutel-waarde. De tests worden uitgevoerd in de context van eenheidstests en op jenkins/job/JOSM. Zij worden ook uitgevoerd voor lokale validatiebestanden als de uitgebreide optievalidator.check_assert_local_rules
is ingesteld op "true" in de uitgebreide voorkeuren (zie #10206). Als u deze optie hebt ingeschakeld en de test mislukt, zult u een bericht in de console-uitvoer krijgen dat eruit kan zien als:WAARSCHUWING: Expecting test '...' to match way ...
or...to not match...
.- Lokale regels voor validatie worden automatisch opnieuw geladen, als zij worden aangepast en opgeslagen door een externe toepassingen. (Het automatisch opnieuw laden kan stoppen, als een fout in de syntaxis in uw validatiebestand een uitzondering produceert in de console. U moet in dat geval JOSM opnieuw opstarten.)
Placeholders
- They are used to simplify the translation and make it less error-prone.
- The placeholders in the warning message e.g.
{3}
are written with ascending numbers, starting at 0. So: 0 1 2 3 4... This is the id of the placeholder. - After the warning message (separated by a comma), you need to define the contents of the placeholders.
- At first you define the content of the first placeholder (the one with the id 0). Then you define the content of the second placeholder (the one with the id 1), and so on.
- You need to specify which selector you want to use in the placeholder and if you want to use the key (
{i.key}
), the value ({i.value}
) or the whole tag ({i.tag}
) of the selector. Counting starts at 0. So,{4.value}
means the value of the 5th selector. - Classes and pseudoclasses do also count.
- You can also use
{i.tag}
for key only selectors. The message will show the actual value of the key (see #10859). - You can use regular expressions in the selector and use this in a placeholder. The message will not show the regexp code but the actual key/value/tag (see #9782).
example:
*[a=b][c=d][e][f=g] { throwWarning: tr("{0} BLA {1} BLUB {2} BLIB {3}", "{1.tag}", "{0.key}", "{2.key}", "{3.value}"); }
This will evaluate to c=d BLA a BLUB e BLIB g
node:unconnected:in-downloaded-area[highway=turning_circle] { throwWarning: tr("{0} must be connected to a way", "{2.tag}"); }
This will evaluate to highway=turning_circle must be connected to a way
. (:unconnected
counts as zeroths placeholder and :in-downloaded-area
counts as first placeholder, therefore highway=turning_circle
is the second placeholder.)
Examples
See *.mapcss
files in source:trunk/data/validator/ for the checks included in JOSM's core or external validator rules.
*[barrier=wire_fence] { throwWarning: tr("{0} is deprecated", "{0.tag}"); /* "{0.tag}" evaluates to "barrier=wire_fence" */ fixAdd: "barrier=fence"; /* You don't need to remove the barrier key before, it will just override with the new value */ fixAdd: "fence_type=chain_link"; assertMatch: "way barrier=wire_fence"; assertNoMatch: "way barrier=fence"; }
usage of classes:
way[highway=~/^(motorway|trunk|primary|secondary|tertiary)$/] { set major_road; } way.major_road[!ref] { throwOther: tr("highway without {0}", "{1.key}"); /* the class ".major:road" is the 0th selector and "!ref" is the 1st selector. The output is: "highway without ref" */ assertMatch: "way highway=primary"; assertNoMatch: "way highway=primary ref=123"; }
See also
- Validator dialog
- Validator preferences and description of validator tests
- Some examples howto use validator