class Pione::PNML::Reader

Public Class Methods

new(src) click to toggle source
# File lib/pione/pnml/reader.rb, line 12
def initialize(src)
  @doc = REXML::Document.new(src)
end
read(location) click to toggle source

Read a PNML file at the location and return ‘PNML::Net`.

@param location [Location::DataLocation]

PNML file's location
# File lib/pione/pnml/reader.rb, line 8
def self.read(location)
  new(location.read).read
end

Public Instance Methods

find_arcs(doc, net) click to toggle source
# File lib/pione/pnml/reader.rb, line 41
def find_arcs(doc, net)
  REXML::XPath.match(doc, "/pnml/net/arc").map do |elt|
    id = elt.attribute("id").value
    source_id = elt.attribute("source").value # source place(data) id
    target_id = elt.attribute("target").value # target transition(rule) id
    Arc.new(net, id, source_id, target_id)
  end
end
find_places(doc, net) click to toggle source
# File lib/pione/pnml/reader.rb, line 33
def find_places(doc, net)
  REXML::XPath.match(doc, "/pnml/net/place").map do |elt|
    id = elt.attribute("id").value
    name = REXML::XPath.first(elt, "name/text").texts.map{|text| text.value}.join("")
    Place.new(net, id, name)
  end
end
find_transitions(doc, net) click to toggle source

Find all transtions in the document.

# File lib/pione/pnml/reader.rb, line 25
def find_transitions(doc, net)
  REXML::XPath.match(doc, "/pnml/net/transition").map do |elt|
    id = elt.attribute("id").value
    name = REXML::XPath.first(elt, "name/text").texts.map{|text| text.value}.join("")
    Transition.new(net, id, name)
  end
end
read() click to toggle source
# File lib/pione/pnml/reader.rb, line 16
def read
  Net.new.tap do |net|
    net.transitions = find_transitions(@doc, net)
    net.places = find_places(@doc, net)
    net.arcs = find_arcs(@doc, net)
  end
end