npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pnml-moddle-converter

v0.2.7

Published

The pnml-moddle-converter is a TypeScript library that provides functionality for converting between PNML (Petri Net Markup Language) and Moddle XML formats. It includes classes for representing different elements of a Petri net, such as places, transitio

Downloads

117

Readme

PNML-Moddle.js Converter

This module provides a parser and serializer for .pnml files and Moddle.js XML files specifying place transition nets. In addition, a converter has been implemented to transform each of the representations into another.

Installation

Use the following command to add this package as a dependency to your node project.

npm i --save pnml-moddle-converter

Usage

Format Conversion

The package can be used as follows (the example can be found in dev.ts):

import { 
  parseModdleXml, 
  parsePnmlXml, 
  convertModdleToPnml, 
  convertPnmlToModdle,
  convertModdleXmlToPnmlXml,
  convertPnmlXmlToModdleXml,
} from "pnml-moddle-converter";

const moddleXml = '<?xml version="1.0" encoding="UTF-8"?>...';
const pnmlXml = '<?xml version="1.0" encoding="UTF-8"?>...';

// Parse a XML file including a Moddle.js place transition net specification
const moddleDefinitions = parseModdleXml(moddleXml);
// Serialize a ModdleDefinitions object into a string
const moddleXml2 = moddleDefinitions.serialize();
// Convert a ModdleDefinitions object into a PnmlDocument object
const pnmlDocumentFromModdle = convertModdleToPnml(moddleDefinitions);
// Directly convert a Moddle XML to a PNML
const pnmlXmlFromModdleXml = convertModdleXmlToPnmlXml(moddleXml);

// Parse a PNML file specifying a place transition net
const pnmlDocument = parsePnmlXml(pnmlXml);
// Serialize a PnmlDocument object into a string
const pnmlXml2 = pnmlDocument.serialize();
// Convert a PnmlDocument object into a ModdleDefinitions object
const moddleDefinitionsFromPnml = convertPnmlToModdle(pnmlDocument);
// Directly convert a PNML to a Moddle XML
const moddleXmlFromPnmlXml = convertPnmlXmlToModdleXml(pnmlXml);

Model Creation

The library can also be used to create models that can be serialized to the corresponding format.

Moddle

Example

const places: ModdlePlace[] = [
  new ModdlePlace({ id: 'place_1', name: 'p_1', marking: 2 }),
  new ModdlePlace({ id: 'place_2', name: 'p_2', marking: 0 }),
];
const transitions: ModdleTransition[] = [
  new ModdleTransition({ id: 'transition_1', name: 't_1' }),
];
const arcs: ModdleArc[] = [
  new ModdleArc({ id: 'arc_1', source: 'place_1', target: 'transition_1', weight: 2}),
  new ModdleArc({ id: 'arc_2', source: 'transition_1', target: 'place_2', weight: 1}),
];

const moddle = new ModdleDefinitions({
  ptNet: new ModdlePTNet({
    id: 'ptnet_id_1', 
    name: 'ptnet_name_1', 
    places, 
    transitions, 
    arcs
  })
});

moddle.serialize();

PNML

Example

const places: PnmlPlace[] = [
  new PnmlPlace({id: "place_1", label: "p_1", initialMarking: 2}),
  new PnmlPlace({id: "place_2", label: "p_2", initialMarking: 0}),
];
const transitions: PnmlTransition[] = [
  new PnmlTransition({id: "transition_1", label: "t_1"}),
];
const arcs: PnmlArc[] = [
  new PnmlArc({id: "arc_1", source: "place_1", target: "transition_1", weight: 2}),
  new PnmlArc({id: "arc_2", source: "transition_1", target: "place_2", weight: 1}),
];

const pnml = new PnmlDocument({
  nets: [
    new PnmlNet({
      id: "net_1",
      name: "net_1",
      type: "http://www.pnml.org/version-2009/grammar/ptnet",
      pages: [
        new PnmlPage({
          id: "page_1",
          places,
          transitions,
          arcs,
        })
      ]
    })
  ]
});

pnml.serialize();

Development

Feel free to contribute to the repository https://github.com/bptlab/pnml-moddle-converter.

You can use the file dev.ts as a sandbox to develop new features. Use the following command to execute the file:

npm run dev