Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8064141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:16:42+00:00 2026-06-05T11:16:42+00:00

As a result of trying to answer the question Graph isomorphism for jar files

  • 0

As a result of trying to answer the question Graph isomorphism for jar files, the debate naturally arose as to how to represent a jar file as a graph using Python.

The problem: given a jar file, read the files contained within it and create a representation of the contents as (a) a data structure and (b) as a graphic, both of them suitable for further study and manipulation, such as, for example, assessing isomorphism with another jar file. In the graph, the tree of directories should be root and branch nodes, ending in files as leaf nodes.

To standardise the answer I use the verletphysics.jar file downloaded from this OpenProcessing sketch.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T11:16:47+00:00Added an answer on June 5, 2026 at 11:16 am

    The Solution

    Given that jar files are basically zipped archives, use the zipfile module from the standard library in Python to read the contents and prepare textual and graphic representation of the relations of the contents of the jar.

    Textual Representation

    For the file verletphysics.jar as mentioned in the question, the code below produces this list of contents:

    META-INF/
    META-INF/MANIFEST.MF
    toxi/
    toxi/physics/
    toxi/physics/behaviors/
    toxi/physics/constraints/
    toxi/physics2d/
    toxi/physics2d/behaviors/
    toxi/physics2d/constraints/
    toxi/physics/ParticlePath.class
    toxi/physics/ParticleString.class
    toxi/physics/PullBackString.class
    toxi/physics/VerletConstrainedSpring.class
    toxi/physics/VerletMinDistanceSpring.class
    toxi/physics/VerletParticle.class
    toxi/physics/VerletPhysics.class
    toxi/physics/VerletSpring.class
    toxi/physics/behaviors/AttractionBehavior.class
    toxi/physics/behaviors/ConstantForceBehavior.class
    toxi/physics/behaviors/GravityBehavior.class
    toxi/physics/behaviors/ParticleBehavior.class
    toxi/physics/constraints/AxisConstraint.class
    toxi/physics/constraints/BoxConstraint.class
    toxi/physics/constraints/CylinderConstraint.class
    toxi/physics/constraints/MaxConstraint.class
    toxi/physics/constraints/MinConstraint.class
    toxi/physics/constraints/ParticleConstraint.class
    toxi/physics/constraints/PlaneConstraint.class
    toxi/physics/constraints/SoftBoxConstraint.class
    toxi/physics/constraints/SphereConstraint.class
    toxi/physics2d/ParticlePath2D.class
    toxi/physics2d/ParticleString2D.class
    toxi/physics2d/PullBackString2D.class
    toxi/physics2d/VerletConstrainedSpring2D.class
    toxi/physics2d/VerletMinDistanceSpring2D.class
    toxi/physics2d/VerletParticle2D.class
    toxi/physics2d/VerletPhysics2D.class
    toxi/physics2d/VerletSpring2D.class
    toxi/physics2d/behaviors/AttractionBehavior.class
    toxi/physics2d/behaviors/ConstantForceBehavior.class
    toxi/physics2d/behaviors/GravityBehavior.class
    toxi/physics2d/behaviors/ParticleBehavior2D.class
    toxi/physics2d/constraints/AngularConstraint.class
    toxi/physics2d/constraints/AxisConstraint.class
    toxi/physics2d/constraints/CircularConstraint.class
    toxi/physics2d/constraints/MaxConstraint.class
    toxi/physics2d/constraints/MinConstraint.class
    toxi/physics2d/constraints/ParticleConstraint2D.class
    toxi/physics2d/constraints/RectConstraint.class
    verletphysics.mf
    

    The Key

    Each node in the above pathnames is extracted and given a unique id by the code, as below:

     Index  File
         0  behaviors
         1  BoxConstraint.class
         2  MaxConstraint.class
         3  VerletParticle.class
         4  ParticleConstraint2D.class
         5  ConstantForceBehavior.class
         6  META-INF
         7  VerletMinDistanceSpring2D.class
         8  AxisConstraint.class
         9  AttractionBehavior.class
        10  physics2d
        11  VerletPhysics.class
        12  PullBackString.class
        13  VerletSpring.class
        14  VerletConstrainedSpring.class
        15  ParticleString2D.class
        16  verletphysics.mf
        17  ParticleBehavior2D.class
        18  ParticleString.class
        19  RectConstraint.class
        20  CylinderConstraint.class
        21  toxi
        22  VerletMinDistanceSpring.class
        23  VerletSpring2D.class
        24  VerletParticle2D.class
        25  ParticlePath2D.class
        26  CircularConstraint.class
        27  ParticlePath.class
        28  MinConstraint.class
        29  MANIFEST.MF
        30  ParticleConstraint.class
        31  GravityBehavior.class
        32  VerletPhysics2D.class
        33  SoftBoxConstraint.class
        34  ParticleBehavior.class
        35  VerletConstrainedSpring2D.class
        36  PlaneConstraint.class
        37  PullBackString2D.class
        38  SphereConstraint.class
        39  physics
        40  AngularConstraint.class
        41  constraints
    

    The Graph

    The pathnames are translated into edges that are built up into this network using NetworkX and plotted with matplotlib.

    network graph of jar file contents

    The Code

    import zipfile
    import networkx as nx
    import matplotlib.pyplot as plt
    
    # Download the code from
    # http://www.openprocessing.org/sketch/46757
    # Unzip and find the jar file: verletphysics.jar
    # This example uses that file for demo
    
    def get_edges(fName):
        edges = []
        nodes = []
    
        jar = zipfile.ZipFile(fName, "r")
        for name in jar.namelist():
            print name # prints the list of files in the jar
            if name.endswith('/'): name = name[:-1]
            parts = name.split('/')
            nodes.extend( parts )
            if len(parts) > 1:
                edges += zip(nodes[:-1], nodes[1:]) 
    
        nodes = set(nodes)
        nodes = dict( zip(nodes, range(len(nodes)) ) )
        edges = [ (nodes[ edge[0] ], nodes[ edge[1] ])
                  for edge in edges ]
        nodes = [ (index, label) for label, index in nodes.iteritems() ]
        nodes = sorted( nodes, key = lambda node: node[0] )
        return set( edges ), nodes
    
    if __name__ == '__main__':
        fName = 'verletphysics.jar'
        edges, nodes = get_edges(fName)
    
        # print list of nodes
        # serving as a key to the graph
        print '%10s  %s' % ('Index', 'File')
        for node in nodes:
            print '%10s  %s' % (node[0], node[1])
    
        # Plot the network graph 
        G = nx.Graph()
        G.add_edges_from( edges )
        nx.draw_networkx(G, pos=nx.spring_layout(G))
        plt.axis('off')
        plt.show()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is as a result of trying Jon Skeet's answer to this question
This question is a result of what i noticed while trying to answer another
Trying to answer this question , I created this Python regular expression to match
I'm trying to represent the result of an MD5 hash in the shortest possible
I was trying to answer another SO question when I hit upon some very
While trying to implement the second answer to a previous question , I am
While trying to answer another question, I was serializing a C# object to an
I am trying to follow answer to question How to get link_to in Rails
This issue came up when trying to answer this question: https://stackoverflow.com/questions/12434634 The documentation for
Using Python (2.7)and sqlite (3) I am trying to copy results of a query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.