Class ConfigParser

java.lang.Object
dev.roanh.gmark.ConfigParser

public final class ConfigParser extends Object
Parser to read complete gMark task configurations.
  • Field Details

    • TO_ELEMENT

      private static final Function<Node,Element> TO_ELEMENT
      Function to cast nodes to elements.
  • Constructor Details

    • ConfigParser

      private ConfigParser()
      Prevent instantiation.
  • Method Details

    • parse

      public static final Configuration parse(Path file) throws ConfigException
      Parses a gMark XML configuration from the given file.
      Parameters:
      file - The file to read from.
      Returns:
      The parsed gMark configuration.
      Throws:
      ConfigException - When something when wrong while parsing the configuration.
    • parse

      public static final Configuration parse(InputStream in) throws ConfigException
      Parses a gMark XML configuration from the given input stream.
      Parameters:
      in - The input stream to read from.
      Returns:
      The parsed gMark configuration.
      Throws:
      ConfigException - When something when wrong while parsing the configuration.
    • parseSchema

      private static final Schema parseSchema(Element elem, List<Type> types, List<Predicate> predicates)
      Parses the schema section of the configuration XML.
      Parameters:
      elem - The schema XML element to parse.
      types - A list of already parsed configuration node types.
      predicates - A list of already parsed configuration predicates.
      Returns:
      The parsed graph schema.
    • parseDistribution

      private static final Distribution parseDistribution(Element elem, String key)
      Parses a distribution section (indistribution or outdistribution) of the configuration XML.
      Parameters:
      elem - The element to parse.
      key - The name of the tag to parse of the element (indistribution or outdistribution).
      Returns:
      The parsed distribution.
    • parseTypes

      private static final List<Type> parseTypes(Element elem)
      Parses the types section of the configuration OutputXML. This section has the following format:
       <types>
           <size>5</size>
           <alias type="0">researcher</alias>
           <proportion type="0">0.5</proportion>
      
           <alias type="1">paper</alias>
           <proportion type="1">0.3</proportion>
      
           <alias type="2">journal</alias>
           <proportion type="2">0.1</proportion>
      
           <alias type="3">conference</alias>
           <proportion type="3">0.1</proportion>
      
           <alias type="4">city</alias>
           <fixed type="4">100</fixed>
       </types>
       
      Parameters:
      elem - The element to parse with the type data.
      Returns:
      The types parsed from the element sorted by ID.
    • parsePredicates

      private static final List<Predicate> parsePredicates(Element elem)
      Parses the predicates section from the configuration OutputXML. This section has the following format:
       <predicates>
           <size>4</size>
           <alias symbol="0">authors</alias>
           <proportion symbol="0">0.5</proportion>
       
           <alias symbol="1">publishedIn</alias>
           <proportion symbol="1">0.3<</proportion>
      
           <alias symbol="2">heldIn</alias>
           <proportion symbol="2">0.01</proportion>
       
           <alias symbol="3">extendedTo</alias>
           <proportion symbol="3">0.19</proportion>
       </predicates>
       
      Parameters:
      elem - The element to parse with the predicate data.
      Returns:
      The parsed predicates from the element sorted by ID.
    • stream

      public static final Stream<Element> stream(Element elem, String name)
      Returns a stream over all the child elements with the given tag name in the given element.
      Parameters:
      elem - The element whose children to stream.
      name - The tag name to filter by.
      Returns:
      A stream over all child elements with the given tag name.
    • stream

      public static final Stream<Node> stream(NodeList list)
      Returns a stream over all the nodes in the given node list.
      Parameters:
      list - The node list to stream.
      Returns:
      A stream over all node list elements.
      See Also:
    • getElement

      public static final Element getElement(Element elem, String name)
      Gets the the child element from the given element with the given tag name. If there are multiple elements that match the given tag name only the first is returned.
      Parameters:
      elem - The element whose child to get.
      name - The tag name of the child to get.
      Returns:
      The child element with the given tag name.
    • forEach

      public static final void forEach(NamedNodeMap data, BiConsumer<String,String> consumer)
      Invokes the given consumer with the name and value of each entry in the given named node map.
      Parameters:
      data - The named node map to iterate.
      consumer - The consumer to invoke with each name value pair.
      See Also: