use of org.hl7.elm.r1.Literal in project kindling by HL7.
the class FhirTurtleGenerator method genBaseMetadata.
/**
* Emit all the basic atoms that are implicit in the actual model
*/
private void genBaseMetadata() {
// Declare these for now - they will get filled in more completely later on
FHIRResource Resource = fact.fhir_class("Resource");
FHIRResource Element = fact.fhir_class("Element");
FHIRResource Reference = fact.fhir_class("Reference");
// Primitive isn't in the actual model - added here
fact.fhir_class("Primitive").addTitle("Types with only a value").addDefinition("Types with only a value and no additional elements as children").restriction(fact.fhir_restriction(value, RDFS.Literal));
// A resource can have an optional nodeRole
FHIRResource treeRoot = fact.fhir_class("treeRoot").addTitle("Class of FHIR base documents");
FHIRResource nodeRole = fact.fhir_objectProperty("nodeRole").addTitle("Identifies role of subject in context of a given document").domain(Resource).range(treeRoot.resource);
Resource.restriction(fact.fhir_cardinality_restriction(nodeRole.resource, treeRoot.resource, 0, 1));
// Any element can have an index to assign order in a list
FHIRResource index = fact.fhir_dataProperty("index").addTitle("Ordering value for list").domain(Element).range(XSD.nonNegativeInteger);
Element.restriction(fact.fhir_cardinality_restriction(index.resource, XSD.nonNegativeInteger, 0, 1));
// References have an optional link
FHIRResource link = fact.fhir_objectProperty("link").addTitle("URI of a reference");
Reference.restriction(fact.fhir_cardinality_restriction(link.resource, Resource.resource, 0, 1));
// XHTML is an XML Literal -- but it isn't recognized by OWL so we use string
FHIRResource NarrativeDiv = fact.fhir_dataProperty("Narrative.div");
fact.fhir_class("xhtml", "Primitive").restriction(fact.fhir_cardinality_restriction(value, fact.fhir_datatype(XSD.xstring).resource, 1, 1));
}
use of org.hl7.elm.r1.Literal in project org.hl7.fhir.core by hapifhir.
the class XhtmlParser method parseLiteral.
private void parseLiteral(StringBuilder s) throws IOException, FHIRFormatError {
// UInt16 w;
readChar();
String c = readUntil(";&'\"><");
if (c.isEmpty())
throw new FHIRFormatError("Invalid literal declaration following text: " + s);
else if (c.charAt(0) == '#') {
if (isInteger(c.substring(1), 10))
s.append((char) Integer.parseInt(c.substring(1)));
else if (c.charAt(1) == 'x' && isInteger(c.substring(2), 16))
s.append((char) Integer.parseInt(c.substring(2), 16));
} else if (entities.containsKey(c)) {
s.append(entities.get(c));
// what's going on here?
// the contents that follow already existed, and then I added the routine to populate the entities
// which was generated from other code. The code that follows is probably redundant, but I haven't
// cross checked it. some is welcome to do so... (GG 8-Nov 2021)
} else if (c.equals("apos"))
s.append('\'');
else if (c.equals("quot"))
s.append('"');
else if (c.equals("nbsp"))
s.append(XhtmlNode.NBSP);
else if (c.equals("amp"))
s.append('&');
else if (c.equals("lsquo"))
// right single quotation, U+2019 ISOnum
s.append((char) 8216);
else if (c.equals("rsquo"))
// right single quotation, U+2019 ISOnum
s.append((char) 8217);
else if (c.equals("gt"))
s.append('>');
else if (c.equals("lt"))
s.append('<');
else if (c.equals("copy"))
s.append((char) 169);
else if (c.equals("reg"))
s.append((char) 174);
else if (c.equals("sect"))
s.append((char) 0xA7);
else if (c.equals("fnof"))
// latin small f with hook = function = florin, U+0192 ISOtech -->
s.append((char) 402);
else if (c.equals("Alpha"))
// greek capital letter alpha, U+0391
s.append((char) 913);
else if (c.equals("Beta"))
// greek capital letter beta, U+0392
s.append((char) 914);
else if (c.equals("Gamma"))
// greek capital letter gamma, U+0393 ISOgrk3
s.append((char) 915);
else if (c.equals("Delta"))
// greek capital letter delta, U+0394 ISOgrk3
s.append((char) 916);
else if (c.equals("Epsilon"))
// greek capital letter epsilon, U+0395
s.append((char) 917);
else if (c.equals("Zeta"))
// greek capital letter zeta, U+0396
s.append((char) 918);
else if (c.equals("Eta"))
// greek capital letter eta, U+0397
s.append((char) 919);
else if (c.equals("Theta"))
// greek capital letter theta, U+0398 ISOgrk3
s.append((char) 920);
else if (c.equals("Iota"))
// greek capital letter iota, U+0399
s.append((char) 921);
else if (c.equals("Kappa"))
// greek capital letter kappa, U+039A
s.append((char) 922);
else if (c.equals("Lambda"))
// greek capital letter lambda, U+039B ISOgrk3
s.append((char) 923);
else if (c.equals("Mu"))
// greek capital letter mu, U+039C
s.append((char) 924);
else if (c.equals("Nu"))
// greek capital letter nu, U+039D
s.append((char) 925);
else if (c.equals("Xi"))
// greek capital letter xi, U+039E ISOgrk3
s.append((char) 926);
else if (c.equals("Omicron"))
// greek capital letter omicron, U+039F
s.append((char) 927);
else if (c.equals("Pi"))
// greek capital letter pi, U+03A0 ISOgrk3
s.append((char) 928);
else if (c.equals("Rho"))
// greek capital letter rho, U+03A1
s.append((char) 929);
else if (c.equals("Sigma"))
// greek capital letter sigma, U+03A3 ISOgrk3
s.append((char) 931);
else if (c.equals("Tau"))
// greek capital letter tau, U+03A4
s.append((char) 932);
else if (c.equals("Upsilon"))
// greek capital letter upsilon, U+03A5 ISOgrk3
s.append((char) 933);
else if (c.equals("Phi"))
// greek capital letter phi, U+03A6 ISOgrk3
s.append((char) 934);
else if (c.equals("Chi"))
// greek capital letter chi, U+03A7
s.append((char) 935);
else if (c.equals("Psi"))
// greek capital letter psi, U+03A8 ISOgrk3
s.append((char) 936);
else if (c.equals("Omega"))
// greek capital letter omega, U+03A9 ISOgrk3
s.append((char) 937);
else if (c.equals("alpha"))
// greek small letter alpha, U+03B1 ISOgrk3
s.append((char) 945);
else if (c.equals("beta"))
// greek small letter beta, U+03B2 ISOgrk3
s.append((char) 946);
else if (c.equals("gamma"))
// greek small letter gamma, U+03B3 ISOgrk3
s.append((char) 947);
else if (c.equals("delta"))
// greek small letter delta, U+03B4 ISOgrk3
s.append((char) 948);
else if (c.equals("epsilon"))
// greek small letter epsilon, U+03B5 ISOgrk3
s.append((char) 949);
else if (c.equals("zeta"))
// greek small letter zeta, U+03B6 ISOgrk3
s.append((char) 950);
else if (c.equals("eta"))
// greek small letter eta, U+03B7 ISOgrk3
s.append((char) 951);
else if (c.equals("theta"))
// greek small letter theta, U+03B8 ISOgrk3
s.append((char) 952);
else if (c.equals("iota"))
// greek small letter iota, U+03B9 ISOgrk3
s.append((char) 953);
else if (c.equals("kappa"))
// greek small letter kappa, U+03BA ISOgrk3
s.append((char) 954);
else if (c.equals("lambda"))
// greek small letter lambda, U+03BB ISOgrk3
s.append((char) 955);
else if (c.equals("mu"))
// greek small letter mu, U+03BC ISOgrk3
s.append((char) 956);
else if (c.equals("nu"))
// greek small letter nu, U+03BD ISOgrk3
s.append((char) 957);
else if (c.equals("xi"))
// greek small letter xi, U+03BE ISOgrk3
s.append((char) 958);
else if (c.equals("omicron"))
// greek small letter omicron, U+03BF NEW
s.append((char) 959);
else if (c.equals("pi"))
// greek small letter pi, U+03C0 ISOgrk3
s.append((char) 960);
else if (c.equals("rho"))
// greek small letter rho, U+03C1 ISOgrk3
s.append((char) 961);
else if (c.equals("sigmaf"))
// greek small letter final sigma, U+03C2 ISOgrk3
s.append((char) 962);
else if (c.equals("sigma"))
// greek small letter sigma, U+03C3 ISOgrk3
s.append((char) 963);
else if (c.equals("tau"))
// greek small letter tau, U+03C4 ISOgrk3
s.append((char) 964);
else if (c.equals("upsilon"))
// greek small letter upsilon, U+03C5 ISOgrk3
s.append((char) 965);
else if (c.equals("phi"))
// greek small letter phi, U+03C6 ISOgrk3
s.append((char) 966);
else if (c.equals("chi"))
// greek small letter chi, U+03C7 ISOgrk3
s.append((char) 967);
else if (c.equals("psi"))
// greek small letter psi, U+03C8 ISOgrk3
s.append((char) 968);
else if (c.equals("omega"))
// greek small letter omega, U+03C9 ISOgrk3
s.append((char) 969);
else if (c.equals("thetasym"))
// greek small letter theta symbol, U+03D1 NEW
s.append((char) 977);
else if (c.equals("upsih"))
// greek upsilon with hook symbol, U+03D2 NEW
s.append((char) 978);
else if (c.equals("piv"))
// greek pi symbol, U+03D6 ISOgrk3
s.append((char) 982);
else if (c.equals("bull"))
// bullet = black small circle, U+2022 ISOpub
s.append((char) 8226);
else if (c.equals("hellip"))
// horizontal ellipsis = three dot leader, U+2026 ISOpub
s.append((char) 8230);
else if (c.equals("prime"))
// prime = minutes = feet, U+2032 ISOtech
s.append((char) 8242);
else if (c.equals("Prime"))
// double prime = seconds = inches, U+2033 ISOtech
s.append((char) 8243);
else if (c.equals("oline"))
// overline = spacing overscore, U+203E NEW
s.append((char) 8254);
else if (c.equals("frasl"))
// fraction slash, U+2044 NEW
s.append((char) 8260);
else if (c.equals("weierp"))
// script capital P = power set = Weierstrass p, U+2118 ISOamso
s.append((char) 8472);
else if (c.equals("image"))
// blackletter capital I = imaginary part, U+2111 ISOamso
s.append((char) 8465);
else if (c.equals("real"))
// blackletter capital R = real part symbol, U+211C ISOamso
s.append((char) 8476);
else if (c.equals("trade"))
// trade mark sign, U+2122 ISOnum
s.append((char) 8482);
else if (c.equals("alefsym"))
// alef symbol = first transfinite cardinal, U+2135 NEW
s.append((char) 8501);
else if (c.equals("larr"))
// leftwards arrow, U+2190 ISOnum
s.append((char) 8592);
else if (c.equals("uarr"))
// upwards arrow, U+2191 ISOnum
s.append((char) 8593);
else if (c.equals("rarr"))
// rightwards arrow, U+2192 ISOnum
s.append((char) 8594);
else if (c.equals("darr"))
// downwards arrow, U+2193 ISOnum
s.append((char) 8595);
else if (c.equals("harr"))
// left right arrow, U+2194 ISOamsa
s.append((char) 8596);
else if (c.equals("crarr"))
// downwards arrow with corner leftwards = carriage return, U+21B5 NEW
s.append((char) 8629);
else if (c.equals("lArr"))
// leftwards double arrow, U+21D0 ISOtech
s.append((char) 8656);
else if (c.equals("uArr"))
// upwards double arrow, U+21D1 ISOamsa
s.append((char) 8657);
else if (c.equals("rArr"))
// rightwards double arrow, U+21D2 ISOtech
s.append((char) 8658);
else if (c.equals("dArr"))
// downwards double arrow, U+21D3 ISOamsa
s.append((char) 8659);
else if (c.equals("hArr"))
// left right double arrow, U+21D4 ISOamsa
s.append((char) 8660);
else if (c.equals("forall"))
// for all, U+2200 ISOtech
s.append((char) 8704);
else if (c.equals("part"))
// partial differential, U+2202 ISOtech
s.append((char) 8706);
else if (c.equals("exist"))
// there exists, U+2203 ISOtech
s.append((char) 8707);
else if (c.equals("empty"))
// empty set = null set = diameter, U+2205 ISOamso
s.append((char) 8709);
else if (c.equals("nabla"))
// nabla = backward difference, U+2207 ISOtech
s.append((char) 8711);
else if (c.equals("isin"))
// element of, U+2208 ISOtech
s.append((char) 8712);
else if (c.equals("notin"))
// not an element of, U+2209 ISOtech
s.append((char) 8713);
else if (c.equals("ni"))
// contains as member, U+220B ISOtech
s.append((char) 8715);
else if (c.equals("prod"))
// n-ary product = product sign, U+220F ISOamsb
s.append((char) 8719);
else if (c.equals("sum"))
// n-ary sumation, U+2211 ISOamsb
s.append((char) 8721);
else if (c.equals("minus"))
// minus sign, U+2212 ISOtech
s.append((char) 8722);
else if (c.equals("lowast"))
// asterisk operator, U+2217 ISOtech
s.append((char) 8727);
else if (c.equals("radic"))
// square root = radical sign, U+221A ISOtech
s.append((char) 8730);
else if (c.equals("prop"))
// proportional to, U+221D ISOtech
s.append((char) 8733);
else if (c.equals("infin"))
// infinity, U+221E ISOtech -->
s.append((char) 8734);
else if (c.equals("ang"))
// angle, U+2220 ISOamso
s.append((char) 8736);
else if (c.equals("and"))
// logical and = wedge, U+2227 ISOtech
s.append((char) 8743);
else if (c.equals("or"))
// logical or = vee, U+2228 ISOtech
s.append((char) 8744);
else if (c.equals("cap"))
// intersection = cap, U+2229 ISOtech
s.append((char) 8745);
else if (c.equals("cup"))
// union = cup, U+222A ISOtech
s.append((char) 8746);
else if (c.equals("int"))
// integral, U+222B ISOtech
s.append((char) 8747);
else if (c.equals("there4"))
// therefore, U+2234 ISOtech
s.append((char) 8756);
else if (c.equals("sim"))
// tilde operator = varies with = similar t U+223C ISOtech
s.append((char) 8764);
else if (c.equals("cong"))
// approximately equal to, U+2245 ISOtec
s.append((char) 8773);
else if (c.equals("asymp"))
// almost equal to = asymptotic to, U+2248 ISOamsr
s.append((char) 8776);
else if (c.equals("ne"))
// not equal to, U+2260 ISOtech
s.append((char) 8800);
else if (c.equals("equiv"))
// identical to, U+2261 ISOtech
s.append((char) 8801);
else if (c.equals("le"))
// less-than or equal to, U+2264 ISOtech
s.append((char) 8804);
else if (c.equals("ge"))
// greater-than or equal to, U+2265 ISOtech
s.append((char) 8805);
else if (c.equals("sub"))
// subset of, U+2282 ISOtech
s.append((char) 8834);
else if (c.equals("sup"))
// superset of, U+2283 ISOtech
s.append((char) 8835);
else if (c.equals("nsub"))
// not a subset of, U+2284 ISOamsn
s.append((char) 8836);
else if (c.equals("sube"))
// subset of or equal to, U+2286 ISOtech
s.append((char) 8838);
else if (c.equals("supe"))
// superset of or equal to, U+2287 ISOtech
s.append((char) 8839);
else if (c.equals("oplus"))
// circled plus = direct sum, U+2295 ISOamsb
s.append((char) 8853);
else if (c.equals("otimes"))
// circled times = vector product, U+2297 ISOamsb -->
s.append((char) 8855);
else if (c.equals("perp"))
// up tack = orthogonal to = perpendicular, U+22A5 ISOtech
s.append((char) 8869);
else if (c.equals("sdot"))
// dot operator, U+22C5 ISOamsb
s.append((char) 8901);
else if (c.equals("lceil"))
// left ceiling = apl upstile, U+2308 ISOamsc
s.append((char) 8968);
else if (c.equals("rceil"))
// right ceiling, U+2309 ISOamsc
s.append((char) 8969);
else if (c.equals("lfloor"))
// left floor = apl downstile, U+230A ISOamsc
s.append((char) 8970);
else if (c.equals("rfloor"))
// right floor, U+230B ISOamsc
s.append((char) 8971);
else if (c.equals("lang"))
// left-pointing angle bracket = bra, U+2329 ISOtech
s.append((char) 9001);
else if (c.equals("rang"))
// right-pointing angle bracket = ket, U+232A ISOtech
s.append((char) 9002);
else if (c.equals("loz"))
// lozenge, U+25CA ISOpub
s.append((char) 9674);
else if (c.equals("spades"))
// black spade suit, U+2660 ISOpub
s.append((char) 9824);
else if (c.equals("clubs"))
// black club suit = shamrock, U+2663 ISOpub
s.append((char) 9827);
else if (c.equals("hearts"))
// black heart suit = valentine, U+2665 ISOpub
s.append((char) 9829);
else if (c.equals("diams"))
// black diamond suit, U+2666 ISOpub --
s.append((char) 9830);
else if (c.equals("ndash"))
s.append((char) 8211);
else if (c.equals("mdash"))
s.append((char) 8212);
else if (c.equals("ldquo"))
s.append((char) 8221);
else if (c.equals("rdquo"))
s.append((char) 201D);
else if (c.equals("frac14"))
s.append((char) 188);
else if (!mustBeWellFormed) {
// we guess that this is an accidentally unescaped &
s.append("&" + c);
} else {
throw new FHIRFormatError("unable to parse character reference '" + c + "'' (last text = '" + lastText + "'" + descLoc());
}
}
use of org.hl7.elm.r1.Literal in project pathling by aehrc.
the class DateLiteralPath method fromString.
/**
* Returns a new instance, parsed from a FHIRPath literal.
*
* @param fhirPath The FHIRPath representation of the literal
* @param context An input context that can be used to build a {@link Dataset} to represent the
* literal
* @return A new instance of {@link LiteralPath}
* @throws ParseException if the literal is malformed
*/
public static DateLiteralPath fromString(@Nonnull final String fhirPath, @Nonnull final FhirPath context) throws ParseException {
final String dateString = fhirPath.replaceFirst("^@", "");
java.util.Date date;
DateLiteralFormat format;
// the year only format.
try {
date = DatePath.getFullDateFormat().parse(dateString);
format = DateLiteralFormat.FULL;
} catch (final ParseException e) {
try {
date = DatePath.getYearMonthDateFormat().parse(dateString);
format = DateLiteralFormat.YEAR_MONTH_DATE;
} catch (final ParseException ex) {
date = DatePath.getYearOnlyDateFormat().parse(dateString);
format = DateLiteralFormat.YEAR_ONLY;
}
}
final DateLiteralPath result = new DateLiteralPath(context.getDataset(), context.getIdColumn(), new DateType(date));
result.format = Optional.of(format);
return result;
}
use of org.hl7.elm.r1.Literal in project pathling by aehrc.
the class DateTimeLiteralPath method fromString.
/**
* Returns a new instance, parsed from a FHIRPath literal.
*
* @param fhirPath The FHIRPath representation of the literal
* @param context An input context that can be used to build a {@link Dataset} to represent the
* literal
* @return A new instance of {@link LiteralPath}
* @throws ParseException if the literal is malformed
*/
public static DateTimeLiteralPath fromString(@Nonnull final String fhirPath, @Nonnull final FhirPath context) throws ParseException {
final String dateTimeString = fhirPath.replaceFirst("^@", "");
final java.util.Date date = DateTimePath.getDateFormat().parse(dateTimeString);
final DateTimeType literalValue = new DateTimeType(date);
literalValue.setTimeZone(DateTimePath.getTimeZone());
return new DateTimeLiteralPath(context.getDataset(), context.getIdColumn(), literalValue);
}
use of org.hl7.elm.r1.Literal in project pathling by aehrc.
the class QuantityLiteralPath method fromString.
/**
* Returns a new instance, parsed from a FHIRPath literal.
*
* @param fhirPath The FHIRPath representation of the literal
* @param context An input context that can be used to build a {@link Dataset} to represent the
* literal
* @return A new instance of {@link LiteralPath}
* @throws IllegalArgumentException if the literal is malformed
*/
@Nonnull
public static QuantityLiteralPath fromString(@Nonnull final String fhirPath, @Nonnull final FhirPath context) throws IllegalArgumentException {
final Matcher matcher = PATTERN.matcher(fhirPath);
if (!matcher.matches()) {
throw new IllegalArgumentException("Quantity literal has invalid format: " + fhirPath);
}
final String rawUnit = matcher.group(2);
final String unit = StringLiteralPath.fromString(rawUnit, context).getLiteralValue().getValueAsString();
final Quantity quantity = new Quantity();
quantity.setUnit(unit);
try {
final long value = IntegerLiteralPath.fromString(fhirPath, context).getLiteralValue().getValue();
quantity.setValue(value);
} catch (final NumberFormatException e) {
try {
final BigDecimal value = DecimalLiteralPath.fromString(fhirPath, context).getLiteralValue().getValue();
quantity.setValue(value);
} catch (final NumberFormatException ex) {
throw new IllegalArgumentException("Quantity literal has invalid format: " + fhirPath);
}
}
return new QuantityLiteralPath(context.getDataset(), context.getIdColumn(), quantity);
}
Aggregations