public void endDocument() throws SAXException { // time to actually set up the edges IntIterator rows = m_edges.rows(); while (rows.hasNext()) { int r = rows.nextInt(); String src = m_edges.getString(r, SRCID); if (!m_nodeMap.containsKey(src)) { throw new SAXException( "Tried to create edge with source node id=" + src + " which does not exist."); } int s = ((Integer) m_nodeMap.get(src)).intValue(); m_edges.setInt(r, SRC, s); String trg = m_edges.getString(r, TRGID); if (!m_nodeMap.containsKey(trg)) { throw new SAXException( "Tried to create edge with target node id=" + trg + " which does not exist."); } int t = ((Integer) m_nodeMap.get(trg)).intValue(); m_edges.setInt(r, TRG, t); } m_edges.removeColumn(SRCID); m_edges.removeColumn(TRGID); // now create the graph m_graph = new Graph(m_nodes, m_edges, m_directed); if (m_graphid != null) m_graph.putClientProperty(ID, m_graphid); }
/** Initialize mapping between prefuse table rows and the rows reported by this model. */ private void initRowMap() { m_rowmap = new int[m_table.getRowCount()]; IntIterator rows = m_table.rows(); for (int i = 0; rows.hasNext(); ++i) { m_rowmap[i] = rows.nextInt(); } }
private Table processJournalName(Table table) throws IOException { ScimapsJournalMatcher scimapsJournalMatcher = new ScimapsJournalMatcher(); // Create new output table Table outputTable = TableUtilities.copyTable(table); outputTable.addColumn(STANDARDIZED_JOURNAL_NAME_COLUMN, String.class); int standardizedJournalNameColumnIndex = outputTable.getColumnNumber(STANDARDIZED_JOURNAL_NAME_COLUMN); // Retrieve iterator Iterator<?> rows = outputTable.tuples(); // Process journal names int rowIndex = 0; while (rows.hasNext()) { Tuple row = (Tuple) rows.next(); if (row.canGetString(journalColumnName)) { String name = row.getString(journalColumnName); String suggestedName = scimapsJournalMatcher.get(name); outputTable.setString(rowIndex, standardizedJournalNameColumnIndex, suggestedName); } rowIndex++; } return outputTable; }
private Table createTableSchema(Schema graphSchema, Table t) { for (int i = 0; i < graphSchema.getColumnCount(); i++) { t.addColumn(graphSchema.getColumnName(i), graphSchema.getColumnType(i)); } t.addColumn(UNIQUE_INDEX_COLUMN_NAME, int.class); t.addColumn(COMBINE_VALUES_COLUMN_NAME, String.class, "*"); return t; }
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { // first clear the character buffer m_sbuf.delete(0, m_sbuf.length()); if (qName.equals(GRAPH)) { // parse directedness default String edef = atts.getValue(EDGEDEF); m_directed = DIRECTED.equalsIgnoreCase(edef); m_graphid = atts.getValue(ID); } else if (qName.equals(KEY)) { if (!inSchema) { error( "\"" + KEY + "\" elements can not" + " occur after the first node or edge declaration."); } m_for = atts.getValue(FOR); m_id = atts.getValue(ID); m_name = atts.getValue(ATTRNAME); m_type = atts.getValue(ATTRTYPE); } else if (qName.equals(NODE)) { schemaCheck(); m_row = m_nodes.addRow(); String id = atts.getValue(ID); m_nodeMap.put(id, new Integer(m_row)); m_table = m_nodes; } else if (qName.equals(EDGE)) { schemaCheck(); m_row = m_edges.addRow(); // do not use the id value // String id = atts.getValue(ID); // if ( id != null ) { // if ( !m_edges.canGetString(ID) ) // m_edges.addColumn(ID, String.class); // m_edges.setString(m_row, ID, id); // } m_edges.setString(m_row, SRCID, atts.getValue(SRC)); m_edges.setString(m_row, TRGID, atts.getValue(TRG)); // currently only global directedness is used // ignore directed edge value for now // String dir = atts.getValue(DIRECTED); // boolean d = m_directed; // if ( dir != null ) { // d = dir.equalsIgnoreCase("false"); // } // m_edges.setBoolean(m_row, DIRECTED, d); m_table = m_edges; } else if (qName.equals(DATA)) { m_key = atts.getValue(KEY); } }
private float compareNodesCaseSensitiveBy( String attributeColumn, Integer nodeOneIndex, Integer nodeTwoIndex, Table nodeTable) { String nodeOneAttribute = (String) nodeTable.getString(nodeOneIndex.intValue(), attributeColumn); String nodeTwoAttribute = (String) nodeTable.getString(nodeTwoIndex.intValue(), attributeColumn); float similarity = this.similarityChecker.getSimilarity(nodeOneAttribute, nodeTwoAttribute); return similarity; }
private DatabaseTable inferTableToBeMerged(Table mergingTable) throws AlgorithmExecutionException { String header = mergingTable.getColumnName(mergingTable.getColumnCount() - 1); String name = extractNameFromHeader(header); try { return DatabaseTable.fromRepresentation(name); } catch (InvalidRepresentationException e) { throw new AlgorithmExecutionException(INVALID_TABLE_NAME_HEADER_MESSAGE); } }
public static JComponent demo() { String datafile = "/amazon.txt"; Table data = null; try { data = (new DelimitedTextTableReader()).readTable(datafile); data.addColumn("image", "CONCAT('/images/',id,'.01.MZZZZZZZ.jpg')"); } catch (Exception e) { e.printStackTrace(); System.exit(1); } return new DataMountain(data); }
private Graph makeEmptyMergeGraph(Table nodeTable) { // same nodes as original graph, but we will build different edges to show which nodes we intend // to merge Table edgeTable = new Table(); edgeTable.addColumn(Graph.DEFAULT_SOURCE_KEY, Integer.TYPE); edgeTable.addColumn(Graph.DEFAULT_TARGET_KEY, Integer.TYPE); edgeTable.addColumn(SIMILARITY_COLUMN_NAME, Float.TYPE); boolean isDirected = false; Graph mergeGraph = new Graph(nodeTable, edgeTable, isDirected); return mergeGraph; }
/** Graph data. */ public GraphData() { super(); nodes = new Table(); nodes.addColumn(NHEADERS[0], NTYPES[0]); nodes.addColumn(NHEADERS[1], NTYPES[1]); nodes.addColumn(NHEADERS[2], NTYPES[2]); edges = new Table(); edges.addColumn(EHEADERS[0], ETYPES[0]); edges.addColumn(EHEADERS[1], ETYPES[1]); edges.addColumn(EHEADERS[2], ETYPES[2]); graph = new Graph(nodes, edges, false, NHEADERS[0], EHEADERS[0], EHEADERS[1]); }
public Data[] execute() { Graph graph = (Graph) data[0].getData(); String attribute = (String) parameters.get("attribute"); String comparator = (String) parameters.get("comparator"); double cutoff = ((Double) parameters.get("cutoff")).doubleValue(); // empty tables with the same schemas as the originals Table nodeTable = graph.getNodeTable().getSchema().instantiate(); Table edgeTable = graph.getEdgeTable().getSchema().instantiate(); // keep all nodes Iterator nodes = graph.getNodeTable().iterator(); while (nodes.hasNext()) { nodeTable.addTuple(graph.getNodeTable().getTuple(((Integer) nodes.next()).intValue())); } // keep all edges matching the criteria Iterator edges = graph.getEdgeTable().iterator(); while (edges.hasNext()) { Tuple tuple = graph.getEdgeTable().getTuple(((Integer) edges.next()).intValue()); Object value = tuple.get(attribute); if (value != null) { if (passes(comparator, ((Number) value).doubleValue(), cutoff)) { edgeTable.addTuple(tuple); } } } Graph resultGraph = new Graph( nodeTable, edgeTable, graph.isDirected(), graph.getNodeKeyField(), graph.getEdgeSourceField(), graph.getEdgeTargetField()); Data result = new BasicData(resultGraph, Graph.class.getName()); Dictionary metadata = result.getMetadata(); metadata.put( DataProperty.LABEL, "Only edges with " + attribute + " " + comparator + " " + cutoff); metadata.put(DataProperty.PARENT, this.data[0]); metadata.put(DataProperty.TYPE, DataProperty.NETWORK_TYPE); return new Data[] {result}; }
/** @see javax.swing.table.TableModel#getValueAt(int, int) */ public Object getValueAt(int rowIndex, int columnIndex) { Object o = m_table.get(getRow(rowIndex), columnIndex); if (o != null && o.getClass().isArray()) { return StringLib.getArrayString(o); } else { return o; } }
private ListMap sortNodesByAttributePrefix( Table nodeTable, String compareAttributeName, int numPrefixLetters) { ListMap nodesByAttributePrefix = new ListMap(); // for each node in the node table... for (IntIterator nodeIndexIt = nodeTable.rows(); nodeIndexIt.hasNext(); ) { int nodeIndex = nodeIndexIt.nextInt(); Tuple row = nodeTable.getTuple(nodeIndex); // get the attribute contents String comparisonAttributeContents = row.getString(compareAttributeName); if (comparisonAttributeContents == null) continue; // add the node index to our list map, in the bin with a key made from a prefix of the // attribute e.g. "do" for "donkey" String prefixKey = extractPrefixKey(comparisonAttributeContents, numPrefixLetters); nodesByAttributePrefix.put(prefixKey, new Integer(nodeIndex)); } return nodesByAttributePrefix; }
// this mutates nodeTable private Table makeMergeTable(Table nodeTable, Graph mergeGraph, StringBuffer mergeLog) { // get all the clusters in our merge graph (where each cluster is a group of nodes to be merged) List clusters = extractWeakComponentClusters(mergeGraph); // for each cluster... for (Iterator clusterIt = clusters.iterator(); clusterIt.hasNext(); ) { LinkedHashSet cluster = (LinkedHashSet) clusterIt.next(); // mark that we will merge every node into a single node // (this step could be made smarter, but is ok for now. Will need user intervention in some // cases) Integer[] eachNodeInCluster = (Integer[]) cluster.toArray(new Integer[cluster.size()]); Integer firstNode = null; if (eachNodeInCluster.length <= 1) continue; for (int ii = 0; ii < eachNodeInCluster.length; ii++) { Integer node = eachNodeInCluster[ii]; if (firstNode == null) { // (we arbitrarily choose the first node as the node to merge other nodes into) firstNode = node; String nodeOneAttribute = (String) nodeTable.getString(firstNode.intValue(), this.compareAttributeName); mergeLog.append("for \"" + nodeOneAttribute + "\"..." + "\r\n"); } else { Integer nodeBeyondFirst = node; // (we merge nodes beyond the first into the first node) // (last value is off by one, because unique indices are 1-based instead of 0-based, but // otherwise correlate with row number. nodeTable.setInt( nodeBeyondFirst.intValue(), UNIQUE_INDEX_COLUMN_NAME, firstNode.intValue() + 1); String iAmNotThePrimaryNodeInCluster = ""; nodeTable.setString( nodeBeyondFirst.intValue(), COMBINE_VALUES_COLUMN_NAME, iAmNotThePrimaryNodeInCluster); String nodeOneAttribute = (String) nodeTable.getString(nodeBeyondFirst.intValue(), this.compareAttributeName); mergeLog.append(" merging in \"" + nodeOneAttribute + "\"" + "\r\n"); } } } return nodeTable; }
/** @see prefuse.data.io.TableWriter#writeTable(prefuse.data.Table, java.io.OutputStream) */ public void writeTable(Table table, OutputStream os) throws DataIOException { try { // get print stream PrintWriter out = new PrintWriter(new OutputStreamWriter(os, "UTF-8")); // write out header row if (m_printHeader) { for (int i = 0; i < table.getColumnCount(); ++i) { if (i > 0) out.print(','); out.print(makeCSVSafe(table.getColumnName(i))); } out.println(); } // write out data for (IntIterator rows = table.rows(); rows.hasNext(); ) { int row = rows.nextInt(); for (int i = 0; i < table.getColumnCount(); ++i) { if (i > 0) out.print(','); String str = table.getString(row, table.getColumnName(i)); out.print(makeCSVSafe(str)); } out.println(); } // finish up out.flush(); } catch (Exception e) { throw new DataIOException(e); } }
private Merger collectMerges(Table mergingTable, DatabaseTable toBeMerged, Connection connection) throws AlgorithmExecutionException { Merger merger = new Merger(toBeMerged, monitor); try { String[] primaryKeyColumns = toBeMerged.getPrimaryKeyColumns(connection); ColumnProjection primaryKeyColumnFilter = new NamedColumnProjection(primaryKeyColumns, true); ForeignKey[] foreignKeys = toBeMerged.getRelations(connection); for (ForeignKey foreignKey : foreignKeys) { // merge units are the units of work that will repoint the foreign keys referring to the // entities merged away to point at the primary entities merger.addMergeUnit(new MergeUnit(foreignKey)); } TableIterator merges = mergingTable.iterator( mergingTable.rowsSortedBy(CreateMergingTable.MERGE_GROUP_IDENTIFIER_COLUMN, true)); while (merges.hasNext()) { int row = merges.nextInt(); Tuple tuple = mergingTable.getTuple(row); String groupIdentifier = tuple.getString(CreateMergingTable.MERGE_GROUP_IDENTIFIER_COLUMN); // for every key someone used for a merge group, there's an EntityGroup EntityGroup group = merger.getOrCreateEntityGroup( groupIdentifier, toBeMerged, primaryKeyColumnFilter, foreignKeys); try { group.addRecord(tuple); } catch (MergingErrorException e) { problems.add(e.getMessage()); } } return merger; } catch (SQLException e) { throw new AlgorithmExecutionException("There was a problem creating the output data.", e); } }
private Graph makeMergeGraph(Table nodeTable, StringBuffer noteLog) { Graph mergeGraph = makeEmptyMergeGraph(nodeTable); // for each group of nodes with a common attribute prefix... ListMap groupedNodes = sortNodesByAttributePrefix(nodeTable, this.compareAttributeName, this.numPrefixLetters); for (Iterator groupIt = groupedNodes.values().iterator(); groupIt.hasNext(); ) { List nodeGroup = (List) groupIt.next(); // for each pair of nodes in the group... for (int i = 0; i < nodeGroup.size(); i++) { Integer firstNodeIndex = (Integer) nodeGroup.get(i); for (int j = i; j < nodeGroup.size(); j++) { Integer secondNodeIndex = (Integer) nodeGroup.get(j); // test how similar the two nodes are float similarity = compareNodesCaseInsensitiveBy( this.compareAttributeName, firstNodeIndex, secondNodeIndex, nodeTable); // if their similarity is high enough to merge... if (similarity >= this.mergeOnSimilarity) { // link the nodes in the merge graph mergeGraph.addEdge(firstNodeIndex.intValue(), secondNodeIndex.intValue()); } // else if their similarity is noteworthy... else if (similarity >= this.makeNoteOnSimilarity) { // record it in the log String nodeOneAttribute = (String) nodeTable.getString(firstNodeIndex.intValue(), this.compareAttributeName); String nodeTwoAttribute = (String) nodeTable.getString(secondNodeIndex.intValue(), this.compareAttributeName); noteLog.append("" + similarity + " similar:" + "\r\n"); noteLog.append(" \"" + nodeOneAttribute + "\"" + "\r\n"); noteLog.append(" \"" + nodeTwoAttribute + "\"" + "\r\n"); } } } } return mergeGraph; }
public void endElement(String namespaceURI, String localName, String qName) { if (qName.equals(DEFAULT)) { // value is in the buffer m_dflt = m_sbuf.toString(); } else if (qName.equals(KEY)) { // time to add to the proper schema(s) addToSchema(); } else if (qName.equals(DATA)) { // value is in the buffer String value = m_sbuf.toString(); String name = (String) m_idMap.get(m_key); Class type = m_table.getColumnType(name); try { Object val = parse(value, type); m_table.set(m_row, name, val); } catch (DataParseException dpe) { error(dpe); } } else if (qName.equals(NODE) || qName.equals(EDGE)) { m_row = -1; m_table = null; } }
private Table populateTable(Table t, Graph g) { for (final Iterator it = g.nodes(); it.hasNext(); ) { final Node n = (Node) it.next(); t.addRow(); for (int i = 0; i < n.getColumnCount(); i++) { t.set(t.getRowCount() - 1, i, n.get(i)); } t.set(t.getRowCount() - 1, UNIQUE_INDEX_COLUMN_NAME, new Integer(t.getRowCount())); } return t; }
@Before public void setUp() { m_vis = new Visualization(); m_t = TableTest.getTestCaseTable(); m_g = GraphTest.getTestCaseGraph(); m_t0 = m_t.getTuple(0); m_n0 = m_g.getNode(0); VisualTable vt = (VisualTable) m_vis.add("t", m_t); VisualGraph vg = (VisualGraph) m_vis.add("g", m_g); m_vt0 = vt.getItem(0); m_vn0 = (NodeItem) vg.getNode(0); TupleSet ts = m_vis.getFocusGroup(Visualization.FOCUS_ITEMS); ts.addTuple(m_vt0); ts.addTuple(m_vn0); }
public void testLoadFromMySQLDatabase() { String host = "localhost"; String database = "friendster"; String user = "******"; String password = ""; String keyField = "uid"; String query1 = "SELECT profiles.* FROM profiles, graph WHERE " + "(graph.uid1 = 186297 AND profiles.uid = graph.uid2)"; String query2 = "SELECT profiles.* FROM profiles, graph WHERE " + "(graph.uid1 = 21721 AND profiles.uid = graph.uid2)"; // String query = "SELECT gender, age, COUNT(*) FROM profiles GROUP BY gender,age"; s_logger.info(TestConfig.memUse()); Table t = null; try { DatabaseDataSource db = ConnectionFactory.getMySQLConnection(host, database, user, password); s_logger.info(TestConfig.memUse()); t = db.getData(t, query1, keyField); db.loadData(t, query2, keyField); } catch (Exception e) { e.printStackTrace(); fail("Error connecting to database"); } // text-dump StringBuffer sbuf = new StringBuffer('\n'); sbuf.append("--[Table: ") .append(t.getRowCount()) .append(" rows, ") .append(t.getColumnCount()) .append(" cols]--\n"); for (int c = 0, idx = -1; c < t.getColumnCount(); ++c) { String name = t.getColumnType(c).getName(); if ((idx = name.lastIndexOf('.')) >= 0) name = name.substring(idx + 1); sbuf.append(c).append("\t").append(name).append("\t").append(t.getColumnName(c)).append('\n'); } sbuf.append('\n'); sbuf.append(TestConfig.memUse()).append('\n'); s_logger.info(sbuf.toString()); m_table = t; }
protected static List<Record> readRecordsFromTable( Table table, LogService logger, String labelColumn, String startDateColumn, String endDateColumn, String sizeByColumn, String startDateFormat, String endDateFormat, String categoryColumn) { List<Record> workingRecordSet = new ArrayList<Record>(); for (Iterator<?> rows = table.tuples(); rows.hasNext(); ) { Tuple row = (Tuple) rows.next(); try { Record newRecord = new Record( row, labelColumn, startDateColumn, endDateColumn, sizeByColumn, startDateFormat, endDateFormat, categoryColumn); workingRecordSet.add(newRecord); } catch (InvalidRecordException e) { logger.log(LogService.LOG_WARNING, "A record was ignored: " + e.getMessage(), e); } } return workingRecordSet; }
/** * Adds a edge. * * @param node1 * @param node2 * @param weight */ public void addEdge(long node1, long node2, double weight) { int row = edges.addRow(); edges.set(row, EHEADERS[0], node1); edges.set(row, EHEADERS[1], node2); edges.set(row, EHEADERS[2], weight); }
/** @see javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int) */ public void setValueAt(Object aValue, int rowIndex, int columnIndex) { m_table.set(getRow(rowIndex), columnIndex, aValue); }
/** @see javax.swing.table.TableModel#getColumnName(int) */ public String getColumnName(int columnIndex) { return m_table.getColumnName(columnIndex); }
private static JToolBar getEncodingToolbar( final ScatterPlot sp, final String xfield, final String yfield, final String sfield) { int spacing = 10; // create list of column names Table t = (Table) sp.getVisualization().getSourceData(group); String[] colnames = new String[t.getColumnCount()]; for (int i = 0; i < colnames.length; ++i) colnames[i] = t.getColumnName(i); // create toolbar that allows visual mappings to be changed JToolBar toolbar = new JToolBar(); toolbar.setLayout(new BoxLayout(toolbar, BoxLayout.X_AXIS)); toolbar.add(Box.createHorizontalStrut(spacing)); final JComboBox xcb = new JComboBox(colnames); xcb.setSelectedItem(xfield); xcb.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Visualization vis = sp.getVisualization(); AxisLayout xaxis = (AxisLayout) vis.getAction("x"); xaxis.setDataField((String) xcb.getSelectedItem()); vis.run("draw"); } }); toolbar.add(new JLabel("X: ")); toolbar.add(xcb); toolbar.add(Box.createHorizontalStrut(2 * spacing)); final JComboBox ycb = new JComboBox(colnames); ycb.setSelectedItem(yfield); ycb.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Visualization vis = sp.getVisualization(); AxisLayout yaxis = (AxisLayout) vis.getAction("y"); yaxis.setDataField((String) ycb.getSelectedItem()); vis.run("draw"); } }); toolbar.add(new JLabel("Y: ")); toolbar.add(ycb); toolbar.add(Box.createHorizontalStrut(2 * spacing)); final JComboBox scb = new JComboBox(colnames); scb.setSelectedItem(sfield); scb.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Visualization vis = sp.getVisualization(); DataShapeAction s = (DataShapeAction) vis.getAction("shape"); s.setDataField((String) scb.getSelectedItem()); vis.run("draw"); } }); toolbar.add(new JLabel("Shape: ")); toolbar.add(scb); toolbar.add(Box.createHorizontalStrut(spacing)); toolbar.add(Box.createHorizontalGlue()); return toolbar; }
/** @see javax.swing.table.TableModel#getColumnClass(int) */ public Class getColumnClass(int columnIndex) { return m_table.getColumnType(columnIndex); }
public Graph toGraph() { Table edgeTable = new Table(); Table nodeTable = new Table(); HashMap<String, Integer> unique = new HashMap<String, Integer>(); edgeTable.addColumn("Node1", int.class); edgeTable.addColumn("Node2", int.class); nodeTable.addColumn("key", int.class); nodeTable.addColumn("name", String.class); nodeTable.addColumn("type", String.class); nodeTable.addColumn("indeterminate", int.class); int idx = 0; for (Protein prot : minProteins.values()) { int row = nodeTable.addRow(); unique.put(prot.getName(), idx); nodeTable.setInt(row, "key", idx++); nodeTable.setString(row, "name", prot.getName()); nodeTable.setString(row, "type", "protein"); nodeTable.setInt(row, "indeterminate", 0); } for (Peptide pep : minPeptides.values()) { int row = nodeTable.addRow(); unique.put(pep.getSequence(), idx); nodeTable.setInt(row, "key", idx++); nodeTable.setString(row, "name", pep.getSequence()); nodeTable.setString(row, "type", "peptide"); if (pep.getIndeterminateType() == PeptideIndeterminacyType.NONE) { nodeTable.setInt(row, "indeterminate", 0); } else { nodeTable.setInt(row, "indeterminate", 1); } } for (Protein prot : minProteins.values()) { int id1 = unique.get(prot.getName()); for (String pep : prot.getPeptides()) { int id2 = unique.get(pep); int row = edgeTable.addRow(); edgeTable.setInt(row, "Node1", id1); edgeTable.setInt(row, "Node2", id2); } } Graph g = new Graph(nodeTable, edgeTable, false, "key", "Node1", "Node2"); // System.err.println(g.getEdgeCount()); return g; }
/** * Adds a menu item to the fisheye menu. * * @param name the menu label to use * @param action the ActionListener to notify when the item is clicked The prefuse VisualItem * corresponding to this menu item will be returned by the ActionEvent's getSource() method. */ public void addMenuItem(String name, ActionListener listener) { int row = m_items.addRow(); m_items.set(row, LABEL, name); m_items.set(row, ACTION, listener); }
/** * Adds a node. * * @param id * @param name * @param picture */ public void addNode(long id, String name, String picture) { int row = nodes.addRow(); nodes.set(row, NHEADERS[0], id); nodes.set(row, NHEADERS[1], name); nodes.set(row, NHEADERS[2], picture); }