Commit 237ca61e authored by Christian MOMON's avatar Christian MOMON
Browse files

Import changes from puck-core-2.3.65-sources.zip.

parent 374e3a1d
......@@ -8,5 +8,6 @@ public enum GraphType {
OreGraph,
TipGraph,
PGraph,
BinaryRelationGraph;
BinaryRelationGraph,
BimodalRelationGraph;
}
......@@ -31,6 +31,7 @@ import org.tip.puck.net.Net;
import org.tip.puck.net.workers.NetUtils;
import org.tip.puck.segmentation.Segmentation;
import org.tip.puck.util.LogHelper;
import org.tip.puck.util.Numberable;
import org.tip.puck.util.PuckUtils;
import fr.devinsy.util.StringList;
......@@ -173,6 +174,13 @@ public class PAJFile {
pajekString = PuckUtils.writePajekNetwork(graph, partitionLabels).toString();
}
break;
case BimodalRelationGraph: {
Graph<Numberable> graph = NetUtils.createBimodalRelationGraph(segmentation);
partitionLabels.add("Mode");
partitionLabels.add("Type");
pajekString = PuckUtils.writePajekNetwork(graph, partitionLabels).toString();
}
break;
default:
throw PuckExceptions.INVALID_PARAMETER.create("Unknown GraphType: [" + graphType + "]");
}
......
......@@ -1002,7 +1002,7 @@ public class Individual implements Comparable<Individual>, Numberable, Attributa
if (this.name == null) {
result = null;
} else {
result = this.name.trim().replaceAll(" / ", "");
result = this.name.trim().replaceAll(" / ", " ");
}
//
return result;
......
......@@ -92,6 +92,23 @@ public class RelationModel {
public Roles roles() {
return this.roles;
}
public int getRoleIndex (Role role){
int result;
result = 0;
for (Role thisRole : roles){
if (thisRole.equals(role)){
break;
}
result++;
}
//
return result;
}
public void setName(final String name) {
this.name = name;
......
......@@ -55,6 +55,7 @@ import org.tip.puck.report.Report;
import org.tip.puck.segmentation.Segment;
import org.tip.puck.segmentation.Segmentation;
import org.tip.puck.statistics.StatisticsWorker;
import org.tip.puck.util.Numberable;
import org.tip.puck.util.NumberablesHashMap.IdStrategy;
import org.tip.puck.util.PuckUtils;
import org.tip.puck.util.Value;
......@@ -928,13 +929,13 @@ public class NetUtils {
Individuals individuals = relation.getIndividuals();
if (individuals.size()==2){
// 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){
......@@ -942,25 +943,53 @@ public class NetUtils {
edgeValues.put(model, edgeValues.size()+1);
edgeValue = edgeValues.get(model);
} else if (model.roles().size()==2){
} else if (model.roles().size()>1){
arcValues.put(model, arcValues.size()+1);
arcValue = arcValues.get(model);
}
}
if (edgeValue != null){
result.addEdge(individuals.getFirst(), individuals.getLast(), edgeValue);
List<Individual> list = individuals.toList();
} else if (arcValue != null) {
for (int i=0;i<list.size();i++){
for (int j=i+1;j<list.size();j++){
result.addEdge(list.get(i), list.get(j), edgeValue);
}
}
}
if (arcValue != null) {
StringList roles = model.roles().toSortedNameList();
List<Individual> sourceList = new ArrayList<Individual>();
List<Individual> targetList = new ArrayList<Individual>();
// Optionalize!
for (int i=0;i<roles.size()-1;i++){
sourceList.addAll(relation.getIndividuals(roles.get(i)).toList());
}
targetList.addAll(relation.getIndividuals(roles.getLast()).toList());
result.addArc(relation.getIndividuals(roles.getFirst()).getFirst(),relation.getIndividuals(roles.getLast()).getFirst(), arcValue);
for (int i=0;i<sourceList.size();i++){
for (int j=0;j<targetList.size();j++){
result.addArc(sourceList.get(i), targetList.get(j), arcValue);
}
}
}
}
}
// }
//
NetUtils.setGenderShapes(result);
......@@ -969,6 +998,49 @@ public class NetUtils {
return result;
}
/**
*
* @param source
* @return
* @throws PuckException
*/
public static Graph<Numberable> createBimodalRelationGraph(final Segmentation source) {
Graph<Numberable> result;
//
result = new Graph<Numberable>("Bimodal Relation graph " + source.getLabel());
//
for (Individual individual : source.getCurrentIndividuals().toSortedList()) {
result.addNode(individual);
result.getNode(individual).setAttribute("Mode", "I");
}
for (Relation relation: source.getCurrentRelations()){
result.addNode(relation);
RelationModel model = relation.getModel();
result.getNode(relation).setAttribute("Type", model.getName());
result.getNode(relation).setAttribute("Mode", "II");
for (Actor actor : relation.actors()){
Individual individual = actor.getIndividual();
int roleIndex = model.getRoleIndex(actor.getRole());
result.addArc(relation, individual, roleIndex+1);
}
}
//
return result;
}
/**
*
* @param source
......
......@@ -60,10 +60,12 @@ public class PajekExportInputDialog extends JDialog {
private JRadioButton rdbtnOregraph;
private JRadioButton rdbtnTipgraph;
private JRadioButton rdbtnRelgraph;
private JRadioButton rdbtnBimodgraph;
private Object[] labels;
private JDialog thisJDialog;
private File file;
private JPanel panelPartitionLabels;
private JRadioButton rdbtnBimodal;
/**
* Create the dialog.
......@@ -126,6 +128,8 @@ public class PajekExportInputDialog extends JDialog {
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");
......@@ -172,6 +176,20 @@ public class PajekExportInputDialog extends JDialog {
panel.add(this.rdbtnRelgraph, "2, 8");
this.buttonGroupGraphType.add(this.rdbtnRelgraph);
}
{
this.rdbtnBimodgraph = new JRadioButton("Bimodal");
this.rdbtnBimodgraph.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
setEnablePartitionlabels(true);
}
});
panel.add(this.rdbtnBimodgraph, "2, 10");
this.buttonGroupGraphType.add(this.rdbtnBimodgraph);
}
}
{
this.panelPartitionLabels = new JPanel();
......@@ -316,6 +334,9 @@ public class PajekExportInputDialog extends JDialog {
if (PajekExportInputDialog.this.rdbtnRelgraph.isSelected()) {
PajekExportInputDialog.this.inputedCriteria.setGraphType(GraphType.BinaryRelationGraph);
}
if (PajekExportInputDialog.this.rdbtnBimodgraph.isSelected()) {
PajekExportInputDialog.this.inputedCriteria.setGraphType(GraphType.BimodalRelationGraph);
}
//
PajekExportInputDialog.this.inputedCriteria.setTargetFileName(targetFile.getAbsolutePath());
......@@ -392,6 +413,10 @@ public class PajekExportInputDialog extends JDialog {
this.rdbtnRelgraph.setSelected(true);
setEnablePartitionlabels(true);
break;
case BimodalRelationGraph:
this.rdbtnBimodgraph.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