Accessing Graph meta data from code

All questions about the GEXF (see http://gexf.net before)
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
Warlax
Posts:18
Joined:19 May 2010 20:45
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
Accessing Graph meta data from code

Post by Warlax » 07 Jul 2010 23:27

Hi,

I've added something meaningful to the GEXF file under the <meta><description> tag.
How can I access this "description" attribute from code?

Thanks,
Warlax.

User avatar
mbastian
Gephi Architect
Posts:728
Joined:10 Dec 2009 10:11
Location:San Francisco, CA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Accessing Graph meta data from code

Post by mbastian » 08 Jul 2010 11:19

These information are not used for the moment. I filled a bug about that issue. Thank you!

Warlax
Posts:18
Joined:19 May 2010 20:45
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Accessing Graph meta data from code

Post by Warlax » 08 Jul 2010 18:13

mbastian,

Thanks for your quick and prompt response. As always, very much appreciated.
Any telling on when this bug will be dealt with?
Is there any other way you can think of that would allow an attribute about the graph/network to be accesible from code?
If there is no way, would you like me to help solve it and contribute the code? If so, could you give me a quick pointer on a comfortable entry-point in the code?
As a workaround, I could add the attribute to the nodes or edges and simply read that in the code - but that's not elegant. What about adding an entry to the <graph><attributes> with class="graph", will that be accessible somehow or will it just fail to parse the GEXF file?

Thanks man, much appreciated.
Warlax

User avatar
mbastian
Gephi Architect
Posts:728
Joined:10 Dec 2009 10:11
Location:San Francisco, CA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Accessing Graph meta data from code

Post by mbastian » 12 Jul 2010 10:00

Is there any other way you can think of that would allow an attribute about the graph/network to be accesible from code?
The best way in my opinion is to store graph attributes into the workspace. In Gephi the workspace represent one graph, a new workspace is created for each file imported. The Workspace is defined in the Project API.
If there is no way, would you like me to help solve it and contribute the code? If so, could you give me a quick pointer on a comfortable entry-point in the code?
Yes, the aim is to allow set/get information about a workspace. The question is if there is always the same information (name, description, keywords, author, ...) or if we want to allow user-defined graph attributes. In both case we have to look at the "getLookup()" method in Workspace. A lookup in Gephi is a service (singleton ususally) container that can be queried with the name of the class. As explained in the Javadoc, it is therefore easy to store new class in a workspace and let other modules query it.

If we want to support graph attributes, and be generic about it, the best way is to add a new table to the Attributes API. Columns for nodes and edges data are managed there. In the AttributeModel we could add a "getGraphTable()" method to allow to store any attribute with graph, i.e. workspace.
When this is done, we need to store values in Workspace. According to Attributes API, values are stored in AttributeRow. Our job is thus to create an instance of AttributeRow and put it in the Workspace's lookup.

That could be done in the Import API, where the files are read and their content appended to the workspace. There, more precisely in Processors, the graph attributes found during GEXF or other formats are appended to the workspace:

Code: Select all

AttributeRow row = workspace.getLookup().lookup(AttributeRow.class);
if(row==null) {
   row = workspace.getLookup().lookup(AttributeModel.class).rowFactory().newGraphRow();
   workspace.add(row);
}
To do that, the Import API has to be modified. The container has to store graph attributes. I can do this part if you prefer.

Warlax
Posts:18
Joined:19 May 2010 20:45
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Accessing Graph meta data from code

Post by Warlax » 29 Jul 2010 19:01

What about getting the path and/or file name of the graph file of the current workspace?
I used this:

Code: Select all

                
    ProjectController pc = Lookup.getDefault().lookup(ProjectController.class); 
    Workspace workspace = pc.getCurrentWorkspace();
But workspace doesn't seem to provide any 'getName()' or 'getFile()' methods.
I can see the 'getLookup' but I don't know what class to pass to it to get the project file name.

User avatar
mbastian
Gephi Architect
Posts:728
Joined:10 Dec 2009 10:11
Location:San Francisco, CA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Accessing Graph meta data from code

Post by mbastian » 03 Aug 2010 21:36

You can query WorkspaceInformation in the Lookup.

Warlax
Posts:18
Joined:19 May 2010 20:45
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Accessing Graph meta data from code

Post by Warlax » 30 Aug 2010 23:08

Hi,

Sorry about the long turn around time for this thread.
I am using WorkspaceInformation to get the source file name for the current workspace:

Code: Select all

        ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
        Workspace workspace = pc.getCurrentWorkspace();
        WorkspaceInformation info = 
            workspace.getLookup().lookup(WorkspaceInformation.class);
        String source = info.getSource();
However, source is just the file name.
Is there a way to get the file path to the file so I can find the file on the file system?

Thanks.

User avatar
mbastian
Gephi Architect
Posts:728
Joined:10 Dec 2009 10:11
Location:San Francisco, CA
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Accessing Graph meta data from code

Post by mbastian » 01 Sep 2010 08:29

Is there a way to get the file path to the file so I can find the file on the file system?
No, this information is not stored in the WorkspaceInformation.

However there is a workaround and you can get the path from the "MostRecentFilesAPI" module:

Code: Select all

List<String> list = Lookup.getDefault.lookup(MostRecentFiles.class).getMRUFileList();
That gives you the last opened files. Hope this helps.

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable