Class ParsingUtils
java.lang.Object
de.iip_ecosphere.platform.configuration.aas.ParsingUtils
Utilities for text parsing.
- Author:
- Holger Eichelberger, SSE
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) static classEncapsulation of enumeration storage structure to enable notifications for multi-row enumeration specifications as in IDTA-02023-0-9. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) static intconsumeNonWhitespaces(String data, int pos) Consumes not-whitespaces starting atpos.(package private) static intconsumeWhitespaces(String data, int pos) Consumes whitespaces starting atpos.(package private) static booleanReturns whetherdatacontainsitemthrough equals.(package private) static intcountSemanticIdMarker(String value) Returns the number of semantic ID markers invalue.(package private) static StringfilterLanguage(String description) Filter English or any other language fromdescriptionif given in multi languages, prefer "definition @" if given.private static StringfilterLanguageImpl(String description) Filter English or any other language fromdescriptionif given in multi languages.(package private) static StringfixTypeName(String name) Checks and fixes a type name.(package private) static StringgetLastNoteComment(String text) Returns the last "Note :" comment intext.private static de.iip_ecosphere.platform.support.logging.LoggerReturns the logger of this class.(package private) static String[]getSemanticIdMarkers(String value) Returns the sequence of semantic ID markers invalue.private static StringgetSemanticIdPrefix(String text) Infers the semanticId prefix oftext.(package private) static booleanhasFixedIdShort(String noteComment) Analyzes an AAS type idShort comment for a note.(package private) static booleanhasSemanticIdMarker(String value) Returns whetherstringstarts with one of the markers inSEMANTICID_MARKER.(package private) static StringinferEnum(ParsingEnumKind kind, String descriptionRest, String idShort, String semanticId, String description, ParsingUtils.AasEnumResultHandler aasEnums, boolean isOpen) Tries to infer an enumeration description from the givendescriptionRest.(package private) static StringinferEnum(String data, String description, AasField field, ParsingUtils.AasEnumResultHandler aasEnums, boolean atBeginning) Tries to infer an enumeration description from the givendescriptionRestbased on the definedenum kinds.private static voidinferEnumEntriesLiteralFromToken(String token, AasEnum en) Infers enumeration literals from a token according toParsingEnumKind.ENUM_ENTRIES.private static voidinferEnumIrdiLiteralsFromToken(String token, AasEnum en) Infers an enumeration literal based on IRDI values.private static voidinferEnumLiteralFromToken(String token, AasEnum en) Infers enumeration literals from a token according toParsingEnumKind.ENUM.private static voidinferValueList2EntriesLiteralFromToken(String token, AasEnum en) Infers value list (2) entries.(package private) static booleanisGenericIdShort(String idShort) Whether a field shall be ignored.(package private) static booleanReturns whethervalis an value to be emitted.(package private) static booleanReturns whethervalis an value to be emitted.private static voidparseEnumEntriesLiteralFromToken(String token, AasEnum en) Parses enum literals viaENUM_LITERAL_PATTERNa given token.(package private) static StringremoveBrackets(String data) Removes surrounding brackets from data.(package private) static StringremoveLinebreaks(String data) Removes linebreaks from data replacing them by a single whitespace.(package private) static StringremovePrefix(String text, String prefix) Iftexthasprefix, returntextwithoutprefix.(package private) static StringremoveQuotes(String value) Removes beautified paired quotes.(package private) static StringremoveSuffix(String text, String suffix) Iftexthassuffix, returntextwithoutsuffix.(package private) static StringremoveWhitespace(String data) Removes whitespaces from data.(package private) static StringreplaceWhitespace(String data, String replacement) Replaces whitespaces in data.(package private) static StringstripRefBy(String type) Strips an IVML refBy declaration and returns the contained type.(package private) static StringtoIdentifier(String name) Turnsnameinto a valid Java/IVML identifier.private static Enumeration<Object> tokenizeEnumSpec(String text, ParsingEnumKind enumKind) Tokenizes an enum specification.private static voidtokenizeEnumSpecValueList2(String text, Vector<Object> tokens) Tokenizes an enum specification according toParsingEnumKind.VALUE_LIST2.(package private) static String[]Splits a string into an array of individual lines.private static StringtoLiteralName(String description) Tries to infer an enum field name fromdescription.(package private) static StringtoNullIfEmpty(String data) Turnsdatato null ifdatais empty.private static StringtoSemanticIdMarker(String value) Turnsvalueinto a semanticID marker.
-
Field Details
-
IRI_MARKER_TEXT
- See Also:
-
IRDI_MARKER_TEXT
- See Also:
-
SEMANTICID_MARKER
-
SEMANTICID_MARKER_WITH_PATH
-
BRACKETS_WIITH_FOOTNOTE
-
ENUM_LITERAL_PATTERN
-
-
Constructor Details
-
ParsingUtils
ParsingUtils()
-
-
Method Details
-
toIdentifier
Turnsnameinto a valid Java/IVML identifier.- Parameters:
name- the name to be processed- Returns:
- the identifier based on
name
-
removeLinebreaks
Removes linebreaks from data replacing them by a single whitespace.- Parameters:
data- the data- Returns:
- the modified version of
data
-
replaceWhitespace
Replaces whitespaces in data.- Parameters:
data- the data (may be null)replacement- the replacement for whitespaces- Returns:
- the modified version of
data
-
removeWhitespace
Removes whitespaces from data.- Parameters:
data- the data- Returns:
- the modified version of
data
-
consumeWhitespaces
Consumes whitespaces starting atpos.- Parameters:
data- the text to iterate overpos- the position to start at- Returns:
- the next position in
datathat is not a whitespace, may be after string length
-
consumeNonWhitespaces
Consumes not-whitespaces starting atpos.- Parameters:
data- the text to iterate overpos- the position to start at- Returns:
- the next position in
datathat is a whitespace, may be after string length
-
toNullIfEmpty
Turnsdatato null ifdatais empty.- Parameters:
data- the string- Returns:
- data or null
-
toLines
Splits a string into an array of individual lines.- Parameters:
data- the string to be split (may be null)- Returns:
- the lines or null if
datawas null
-
removeBrackets
Removes surrounding brackets from data.- Parameters:
data- the data to be processed- Returns:
dataordatawith surrounding brackets, then whitespaces removed- See Also:
-
fixTypeName
Checks and fixes a type name. In some specs, there is additional information or typos such as cardinalities. Is some specs, the type name is in brackets. This information is removed.- Parameters:
name- the type name- Returns:
nameor a shortened version- See Also:
-
getLastNoteComment
Returns the last "Note :" comment intext.- Parameters:
text- the text to take the comment from- Returns:
- the comment including "Note: ", null if there is none
-
hasFixedIdShort
Analyzes an AAS type idShort comment for a note.- Parameters:
noteComment- the note comment- Returns:
truefor fixed idShort,falsefor free idShort
-
inferEnum
static String inferEnum(String data, String description, AasField field, ParsingUtils.AasEnumResultHandler aasEnums, boolean atBeginning) Tries to infer an enumeration description from the givendescriptionRestbased on the definedenum kinds.- Parameters:
data- the actual part containing the enumeration textdescription- the actual description textfield- the target field (to be modified as a side effect)aasEnums- the known enums, to be modified as a side effectatBeginning- whether the enum marker may be at the very beginning ofdataor not- Returns:
descriptionor an updated/modified text
-
inferEnum
static String inferEnum(ParsingEnumKind kind, String descriptionRest, String idShort, String semanticId, String description, ParsingUtils.AasEnumResultHandler aasEnums, boolean isOpen) Tries to infer an enumeration description from the givendescriptionRest.- Parameters:
kind- the enumeration kinddescriptionRest- the description rest that potentially contains a flattened, comma-separated description of enum literalsidShort- the idShort of the containing fieldsemanticId- optional semantic id of the enumdescription- the description of the enumaasEnums- the known enums, to be modified as a side effectisOpen- whether the enum is considered to be "open" for extensions- Returns:
- the type name of the enum (for now, just
idShort)
-
tokenizeEnumSpec
Tokenizes an enum specification. Prevents token splitting within parentheses.- Parameters:
text- the text to tokenizeenumKind- the kind of enum to tokenize- Returns:
- the token enumeration (compliant to
StringTokenizer
-
tokenizeEnumSpecValueList2
Tokenizes an enum specification according toParsingEnumKind.VALUE_LIST2.- Parameters:
text- the text to tokenizetokens- the tokens (compliant toStringTokenizer
-
inferEnumLiteralFromToken
Infers enumeration literals from a token according toParsingEnumKind.ENUM.- Parameters:
token- the tokenen- the enumeration to add the literals to
-
inferValueList2EntriesLiteralFromToken
Infers value list (2) entries. IDTA-02010-1-0- Parameters:
token- the tokenen- the enumeration to be modified as a side effect
-
inferEnumIrdiLiteralsFromToken
Infers an enumeration literal based on IRDI values. IDTA-02004-1-2.- Parameters:
token- the token containing the literal(s)en- the enum to complement with literals
-
getSemanticIdPrefix
Infers the semanticId prefix oftext.- Parameters:
text- the text to use as basis- Returns:
- the semanticId prefix as in
IdentifierType, may be null for none
-
inferEnumEntriesLiteralFromToken
Infers enumeration literals from a token according toParsingEnumKind.ENUM_ENTRIES.- Parameters:
token- the tokenen- the enumeration to add the literals to
-
removeQuotes
Removes beautified paired quotes.- Parameters:
value- the value to be processed- Returns:
- the processed value
-
parseEnumEntriesLiteralFromToken
Parses enum literals viaENUM_LITERAL_PATTERNa given token.- Parameters:
token- the tokenen- the enumeration to add the literal to
-
toLiteralName
Tries to infer an enum field name fromdescription.- Parameters:
description- the description- Returns:
- the field name or
description
-
filterLanguage
Filter English or any other language fromdescriptionif given in multi languages, prefer "definition @" if given.- Parameters:
description- the description- Returns:
- the last language-specific description
-
filterLanguageImpl
Filter English or any other language fromdescriptionif given in multi languages.- Parameters:
description- the description- Returns:
- the last language-specific description
-
isGenericIdShort
Whether a field shall be ignored.- Parameters:
idShort- the idShort to test (may be null)- Returns:
truefor ignore,falseelse
-
toSemanticIdMarker
Turnsvalueinto a semanticID marker.- Parameters:
value- the value- Returns:
- the marker
-
getSemanticIdMarkers
Returns the sequence of semantic ID markers invalue.- Parameters:
value- the value- Returns:
- the number of semantic IDs
-
countSemanticIdMarker
Returns the number of semantic ID markers invalue.- Parameters:
value- the value- Returns:
- the number of semantic IDs
-
hasSemanticIdMarker
Returns whetherstringstarts with one of the markers inSEMANTICID_MARKER.- Parameters:
value- the value to check- Returns:
trueif a semanticId marker was found,falseelse
-
removeSuffix
Iftexthassuffix, returntextwithoutsuffix.- Parameters:
text- the textsuffix- the suffix- Returns:
textortextwithoutsuffix
-
removePrefix
Iftexthasprefix, returntextwithoutprefix.- Parameters:
text- the textprefix- the prefix- Returns:
textortextwithoutprefix
-
contains
Returns whetherdatacontainsitemthrough equals.- Parameters:
data- the data to searchitem- the item to look for- Returns:
trueif contained,falseelse
-
isValue
Returns whethervalis an value to be emitted.- Parameters:
val- the value- Returns:
truefor emitting,falsefor skipping
-
isValue
Returns whethervalis an value to be emitted.- Parameters:
val- the value- Returns:
truefor emitting,falsefor skipping
-
stripRefBy
Strips an IVML refBy declaration and returns the contained type.- Parameters:
type- the type- Returns:
typeortypewithout refBy
-
getLogger
private static de.iip_ecosphere.platform.support.logging.Logger getLogger()Returns the logger of this class.- Returns:
- the logger
-