Commit a465d99c authored by Klaus Hamberger's avatar Klaus Hamberger
Browse files

Added Pajek export of binary relations.

git-svn-id: svn+ssh://svn.code.sf.net/p/tip-puck/code/trunk@2342 fbf60bc9-78ff-467a-80f5-d9f1d8e511fc
parent c0f43c0b
......@@ -7,5 +7,6 @@ package org.tip.puck.graphs;
public enum GraphType {
OreGraph,
TipGraph,
PGraph;
PGraph,
BinaryRelationGraph;
}
......@@ -168,6 +168,11 @@ public class PAJFile {
pajekString = PuckUtils.writePajekNetwork(graph, partitionLabels).toString();
}
break;
case BinaryRelationGraph: {
Graph<Individual> graph = NetUtils.createBinaryRelationGraph(segmentation);
pajekString = PuckUtils.writePajekNetwork(graph, partitionLabels).toString();
}
break;
default:
throw PuckExceptions.INVALID_PARAMETER.create("Unknown GraphType: [" + graphType + "]");
}
......
......@@ -33,7 +33,6 @@ import org.tip.puck.net.Families;
import org.tip.puck.net.Family;
import org.tip.puck.net.FiliationType;
import org.tip.puck.net.Gender;
import org.tip.puck.net.Gender.GenderCode;
import org.tip.puck.net.Individual;
import org.tip.puck.net.Individuals;
import org.tip.puck.net.KinType;
......@@ -45,6 +44,7 @@ import org.tip.puck.net.relations.Relation;
import org.tip.puck.net.relations.RelationModel;
import org.tip.puck.net.relations.Relations;
import org.tip.puck.net.relations.Role;
import org.tip.puck.net.relations.Roles;
import org.tip.puck.net.workers.AttributeWorker.Scope;
import org.tip.puck.net.workers.UpdateWorker.UpdateMode;
import org.tip.puck.partitions.Cluster;
......@@ -904,6 +904,71 @@ public class NetUtils {
return result;
}
/**
*
* @param source
* @return
* @throws PuckException
*/
public static Graph<Individual> createBinaryRelationGraph(final Segmentation source) {
Graph<Individual> result;
//
result = new Graph<Individual>("MultiRelation graph " + source.getLabel());
//
for (Individual individual : source.getCurrentIndividuals().toSortedList()) {
result.addNode(individual);
}
Map<RelationModel,Integer> edgeValues = new HashMap<RelationModel,Integer>();
Map<RelationModel,Integer> arcValues = new HashMap<RelationModel,Integer>();
for (Relation relation: source.getCurrentRelations()){
Individuals individuals = relation.getIndividuals();
if (individuals.size()==2){
RelationModel model = relation.getModel();
Integer edgeValue = edgeValues.get(model);
Integer arcValue = arcValues.get(model);
if (edgeValue == null && arcValue == null){
if (model.roles().size()==1){
edgeValues.put(model, edgeValues.size()+1);
edgeValue = edgeValues.get(model);
} else if (model.roles().size()==2){
arcValues.put(model, arcValues.size()+1);
arcValue = arcValues.get(model);
}
}
if (edgeValue != null){
result.addEdge(individuals.getFirst(), individuals.getLast(), edgeValue);
} else if (arcValue != null) {
StringList roles = model.roles().toSortedNameList();
result.addArc(relation.getIndividuals(roles.getFirst()).getFirst(),relation.getIndividuals(roles.getLast()).getFirst(), arcValue);
}
}
}
//
NetUtils.setGenderShapes(result);
//
return result;
}
/**
*
* @param source
......
......@@ -59,6 +59,7 @@ public class PajekExportInputDialog extends JDialog {
private JComboBox cmbbxLabel5;
private JRadioButton rdbtnOregraph;
private JRadioButton rdbtnTipgraph;
private JRadioButton rdbtnRelgraph;
private Object[] labels;
private JDialog thisJDialog;
private File file;
......@@ -110,10 +111,22 @@ public class PajekExportInputDialog extends JDialog {
JPanel panel = new JPanel();
panel.setBorder(new TitledBorder(null, "Graph Type", TitledBorder.LEADING, TitledBorder.TOP, null, null));
this.contentPanel.add(panel, "2, 2, fill, fill");
panel.setLayout(new FormLayout(new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC,
FormFactory.DEFAULT_COLSPEC, FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, }, new RowSpec[] {
FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, }));
panel.setLayout(new FormLayout(new ColumnSpec[] {
FormFactory.RELATED_GAP_COLSPEC,
FormFactory.DEFAULT_COLSPEC,
FormFactory.RELATED_GAP_COLSPEC,
FormFactory.DEFAULT_COLSPEC,
FormFactory.RELATED_GAP_COLSPEC,
FormFactory.DEFAULT_COLSPEC,},
new RowSpec[] {
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,
FormFactory.RELATED_GAP_ROWSPEC,
FormFactory.DEFAULT_ROWSPEC,}));
{
this.rdbtnOregraph = new JRadioButton("Ore-Graph");
this.rdbtnOregraph.addActionListener(new ActionListener() {
......@@ -148,6 +161,17 @@ public class PajekExportInputDialog extends JDialog {
panel.add(this.rdbtnPgraph, "2, 6");
this.buttonGroupGraphType.add(this.rdbtnPgraph);
}
{
this.rdbtnRelgraph = new JRadioButton("Relations");
this.rdbtnRelgraph.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
setEnablePartitionlabels(true);
}
});
panel.add(this.rdbtnRelgraph, "2, 8");
this.buttonGroupGraphType.add(this.rdbtnRelgraph);
}
}
{
this.panelPartitionLabels = new JPanel();
......@@ -244,6 +268,7 @@ public class PajekExportInputDialog extends JDialog {
btnExport.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
//
if (StringUtils.isBlank(PajekExportInputDialog.this.txtfldTargetFile.getText())) {
//
......@@ -260,10 +285,12 @@ public class PajekExportInputDialog extends JDialog {
if (targetFile.exists()) {
//
String title = "Confirm";
String message = "A file already exists with name, erase?.";
String message = "A file already exists with name, erase?";
System.out.println(message);
//
int response = JOptionPane.showConfirmDialog(null, message, title, JOptionPane.YES_NO_OPTION);
int response = JOptionPane.showConfirmDialog(PajekExportInputDialog.this.contentPanel, message, title, JOptionPane.YES_NO_OPTION);
if (response == JOptionPane.YES_OPTION) {
doExport = true;
......@@ -288,7 +315,10 @@ public class PajekExportInputDialog extends JDialog {
if (PajekExportInputDialog.this.rdbtnPgraph.isSelected()) {
PajekExportInputDialog.this.inputedCriteria.setGraphType(GraphType.PGraph);
}
if (PajekExportInputDialog.this.rdbtnRelgraph.isSelected()) {
PajekExportInputDialog.this.inputedCriteria.setGraphType(GraphType.BinaryRelationGraph);
}
//
PajekExportInputDialog.this.inputedCriteria.setTargetFileName(targetFile.getAbsolutePath());
......@@ -346,6 +376,7 @@ public class PajekExportInputDialog extends JDialog {
this.rdbtnOregraph.setSelected(false);
this.rdbtnPgraph.setSelected(false);
this.rdbtnTipgraph.setSelected(false);
this.rdbtnRelgraph.setSelected(false);
switch (source.getGraphType()) {
case OreGraph:
this.rdbtnOregraph.setSelected(true);
......@@ -359,6 +390,10 @@ public class PajekExportInputDialog extends JDialog {
this.rdbtnTipgraph.setSelected(true);
setEnablePartitionlabels(true);
break;
case BinaryRelationGraph:
this.rdbtnRelgraph.setSelected(true);
setEnablePartitionlabels(true);
break;
}
//
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment