use of org.gephi.io.importer.api.Issue in project gephi by gephi.
the class ImporterTGF method importData.
private void importData(LineNumberReader reader) throws Exception {
//Progress
Progress.start(progressTicket);
List<String> nodes = new ArrayList<>();
List<String> edges = new ArrayList<>();
boolean isNode = true;
for (; reader.ready(); ) {
String line = reader.readLine().trim();
if ("#".equalsIgnoreCase(line)) {
isNode = false;
} else if (line != null && !line.isEmpty()) {
if (isNode) {
nodes.add(line);
} else {
edges.add(line);
}
}
}
Progress.switchToDeterminate(progressTicket, nodes.size() + edges.size());
if (nodes.isEmpty()) {
report.logIssue(new Issue(NbBundle.getMessage(ImporterTGF.class, "importerTGF_error_emptynodes"), Issue.Level.CRITICAL));
}
for (String n : nodes) {
addNode(n.substring(0, n.indexOf(" ")), n.substring(n.indexOf(" ")));
}
//Progress
Progress.progress(progressTicket);
for (String e : edges) {
int firstSpace = e.indexOf(" ");
int secondSpace = e.indexOf(" ", firstSpace + 1);
String[] tempFields = e.split(" ");
String from = tempFields[0];
String to = tempFields[1];
addEdge(from, to, e.substring(secondSpace));
}
//Progress
Progress.progress(progressTicket);
}
use of org.gephi.io.importer.api.Issue in project gephi by gephi.
the class ImporterVNA method execute.
@Override
public boolean execute(ContainerLoader container) {
this.container = container;
this.report = new Report();
LineNumberReader lineReader = ImportUtils.getTextReader(reader);
try {
importData(lineReader);
} catch (Exception e) {
report.logIssue(new Issue(e, Issue.Level.SEVERE));
} finally {
try {
lineReader.close();
} catch (IOException ex) {
}
}
return !cancel;
}
use of org.gephi.io.importer.api.Issue in project gephi by gephi.
the class ImporterVNA method importData.
private void importData(LineNumberReader reader) throws Exception {
List<String> lines = new ArrayList<>();
while (reader.ready()) {
String line = reader.readLine();
if (line != null && !line.isEmpty()) {
lines.add(line);
}
}
State state = State.DEFAULT;
Progress.start(progressTicket, lines.size());
String[] split;
final Pattern nodeDataPattern = Pattern.compile("^\\*node data\\s*", Pattern.CASE_INSENSITIVE);
final Pattern nodePropertiesPattern = Pattern.compile("^\\*node properties\\s*", Pattern.CASE_INSENSITIVE);
final Pattern tieDataPattern = Pattern.compile("^\\*tie data\\s*", Pattern.CASE_INSENSITIVE);
for (String line : lines) {
if (cancel) {
return;
}
if (nodeDataPattern.matcher(line).matches()) {
state = State.NODE_DATA_DEF;
continue;
} else if (nodePropertiesPattern.matcher(line).matches()) {
state = State.NODE_PROPERTIES_DEF;
continue;
} else if (tieDataPattern.matcher(line).matches()) {
state = State.TIE_DATA_DEF;
continue;
}
switch(state) {
case NODE_DATA_DEF:
String[] nodeDataLabels = line.split("[\\s,]+");
nodeDataColumns = new ColumnDraft[nodeDataLabels.length];
for (int i = 1; i < nodeDataLabels.length; i++) {
nodeDataColumns[i] = container.addNodeColumn(nodeDataLabels[i], String.class);
}
state = State.NODE_DATA;
break;
case NODE_PROPERTIES_DEF:
// Initialize node properties labels and fill nodeAttributes
// if some attributes can be used for NodeDraft
nodePropertiesLabels = line.split("[\\s,]+");
nodeDataAttributes = new Attributes[nodePropertiesLabels.length];
for (int i = 1; i < nodePropertiesLabels.length; i++) {
if (nodePropertiesLabels[i].equalsIgnoreCase("x")) {
nodeDataAttributes[i] = Attributes.NODE_X;
} else if (nodePropertiesLabels[i].equalsIgnoreCase("y")) {
nodeDataAttributes[i] = Attributes.NODE_Y;
} else if (nodePropertiesLabels[i].equalsIgnoreCase("color")) {
nodeDataAttributes[i] = Attributes.NODE_COLOR;
} else if (nodePropertiesLabels[i].equalsIgnoreCase("size")) {
nodeDataAttributes[i] = Attributes.NODE_SIZE;
} else if (nodePropertiesLabels[i].equalsIgnoreCase("shortlabel")) {
nodeDataAttributes[i] = Attributes.NODE_SHORT_LABEL;
} else if (nodePropertiesLabels[i].equalsIgnoreCase("shape")) {
nodeDataAttributes[i] = Attributes.NODE_SHAPE;
} else {
throw new RuntimeException("Unexpected node parameter at line '" + line + "';");
}
}
state = State.NODE_PROPERTIES;
break;
case TIE_DATA_DEF:
String[] tieDataLabels = line.split("[\\s,]+");
tieDataColumns = new ColumnDraft[tieDataLabels.length];
tieAttributes = new Attributes[tieDataColumns.length];
if (tieDataColumns.length < 2) {
throw new RuntimeException("Edge data labels definition does not contain two necessary variables ('from' and 'to').");
}
// attributes can be used for EdgeDraft
for (int i = 2; i < tieDataColumns.length; i++) {
if (tieDataLabels[i].equalsIgnoreCase("strength")) {
tieAttributes[i] = Attributes.EDGE_STRENGTH;
} else {
tieAttributes[i] = Attributes.OTHER;
tieDataColumns[i] = container.addEdgeColumn(tieDataLabels[i], String.class);
}
}
state = State.TIE_DATA;
break;
case NODE_DATA:
// new node
split = split(line);
if (split.length != nodeDataColumns.length) {
report.logIssue(new Issue("Number of labels and number of data mismatch in: '" + line + "'", Issue.Level.WARNING));
break;
}
addNode(split);
// parse - if parse error => LOG error
break;
case NODE_PROPERTIES:
split = split(line);
if (split.length != nodePropertiesLabels.length) {
report.logIssue(new Issue("Number of labels and number of data mismatch in: '" + line + "'", Issue.Level.WARNING));
break;
}
addNodeProperties(split);
// parse - if parse error => LOG error
break;
case TIE_DATA:
split = split(line);
if (split.length != tieDataColumns.length) {
report.logIssue(new Issue("Number of labels and number of data mismatch in: '" + line + "'", Issue.Level.WARNING));
break;
}
addEdge(split);
// parse - if parse error => LOG error
break;
}
Progress.progress(progressTicket);
}
}
use of org.gephi.io.importer.api.Issue in project gephi by gephi.
the class ReportPanel method fillIssues.
private void fillIssues(Report report) {
final List<Issue> issues = new ArrayList<>();
Iterator<Issue> itr = report.getIssues(ISSUES_LIMIT);
while (itr.hasNext()) {
issues.add(itr.next());
}
if (issues.isEmpty()) {
JLabel label = new JLabel(NbBundle.getMessage(getClass(), "ReportPanel.noIssues"));
label.setHorizontalAlignment(SwingConstants.CENTER);
tab1ScrollPane.setViewportView(label);
} else {
//Busy label
final BusyUtils.BusyLabel busyLabel = BusyUtils.createCenteredBusyLabel(tab1ScrollPane, "Retrieving issues...", issuesOutline);
//Thread
Thread thread = new Thread(fillingThreads, new Runnable() {
@Override
public void run() {
busyLabel.setBusy(true);
final TreeModel treeMdl = new IssueTreeModel(issues);
final OutlineModel mdl = DefaultOutlineModel.createOutlineModel(treeMdl, new IssueRowModel(), true);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
issuesOutline.setRootVisible(false);
issuesOutline.setRenderDataProvider(new IssueRenderer());
issuesOutline.setModel(mdl);
busyLabel.setBusy(false);
}
});
}
}, "Report Panel Issues Outline");
if (NbPreferences.forModule(ReportPanel.class).getBoolean(SHOW_ISSUES, true)) {
thread.start();
}
}
}
use of org.gephi.io.importer.api.Issue in project gephi by gephi.
the class ImportContainerImpl method addEdgeColumn.
@Override
public ColumnDraft addEdgeColumn(String key, Class typeClass, boolean dynamic) {
key = key.toLowerCase();
ColumnDraft column = edgeColumns.get(key);
typeClass = AttributeUtils.getStandardizedType(typeClass);
if (column == null) {
int index = edgeColumns.size();
column = new ColumnDraftImpl(key, index, dynamic, typeClass);
edgeColumns.put(key, column);
if (dynamic) {
report.log(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerLog.AddDynamicEdgeColumn", key, typeClass.getSimpleName()));
} else {
report.log(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerLog.AddEdgeColumn", key, typeClass.getSimpleName()));
}
} else if (!column.getTypeClass().equals(typeClass)) {
report.logIssue(new Issue(NbBundle.getMessage(ImportContainerImpl.class, "ImportContainerException_Column_Type_Mismatch", key, column.getTypeClass()), Level.SEVERE));
}
return column;
}
Aggregations