I need to parse the rather arcane FCC Emission Designator using SPARQL/SPIN from a compound string encoding to values I can easily reason over. The first task is to get the "required bandwidth" out of the designator. Here are examples of what the emission designators look like (available as xsd:string
values) and the corresponding required bandwidths, manually interpreted my little old me:
16K00F3E
16.00 kHz or 16,000.0 Hz3K00J3E
3.00 kHz or 3,000.0 Hz1K10F1B
1.10 kHz or 1,100.0 Hz100H00A1A
100.00 Hz10M0G2D
10.0 MHz or 10,000,000.00 Hz
Ultimately I want to get to xsd:double
values in Hz, but I'm presently stuck on the first step, getting the required bandwidth substring out of the whole emission designator string.
The regular expression ^[0-9]+[A-Z][0-9]+
does the trick for this first step. For example, this regular expression applied to the emission designator 10M0G2D
matches 10M0
.
The required bandwidth substring I want is, in practice, variable-length. It has a set of numbers, a letter (see below), and then another set of numbers. The letter marks the decimal point and determines the multiplier:
H
- If the value is less than 1000 Hz (muliplier is 1.0)K
- 1 kHz to values less than 1000 kHz (multiplier is 1000.0)M
- 1 MHz to values less than 1000 MHz (multiplier is 1,000,000.0)G
- 1 GHz or greater (multiplier is 1,000,000,000.0)
This is followed by another letter which is outside the required bandwidth.
So, my question is, in SPARQL/SPIN, how do I get the required bandwidth substring as defined in the above regular expression parsed out of the emission designator string? I want to bind that substring to a SPARQL variable, say ?encodedRequiredBandwidth
. The only use of a regular expression I see in SPARQL/SPIN is xsd:boolean REGEX (simple literal text, simple literal pattern)
. That's great, but I want the substring matching the regex, not a flag indicating it's in there somwhere.
Any ideas on how to get my required bandwidth substring?
Any ideas on how to to the remainder of the parsing to get to an xsd:double
Hz value that I can reason over easily (e.g. do magnitude comparisons)?
Thanks.
I now also have ugly SPARQL code to complete the conversion of the bandwidth to an
xsd:double
. This is predicated on the assumption that the frequency designator occurs in the first 6 characters of the encoded bandwdith. The standard constrains the entire bandwidth field to 4 characters including the designator. However, I've seen examples extended up to 6 characters (e.g. the100H00
shown above which could just as well been compliantly encoded as100H
)Here's the SPARQL code self-contained example:
The above gives the result shown below... with the double-precision value of the bandwidth in
?bandwidthDouble
as Hz which makes subsequent reasoning convenient. Now on to handling the rest of the emission designator. Ultimately, this code will end up in SPIN constructors to do automated translation upon instantiation.