int count = statistics.getTotalTriples(); message = String.format("%s %s", count, (count == 1 ? "triple" : "triples")); final HashMap<String, HashMap<String, Integer>> data = statistics.getStatistics(); for (String datasourceName : data.keySet() ) {
/** * Returns one triple count from a particular mapping. * * @param datasourceId * The data source identifier. * @param mappingId * The mapping identifier. * @return The number of triples. */ public int getStatistics(String datasourceId, String mappingId) { final HashMap<String, Integer> mappingStat = getStatistics(datasourceId); int triplesCount = mappingStat.get(mappingId).intValue(); return triplesCount; }
public void refresh() { OBDADataSource source = obdaModel.getDatasource(); List<SQLPPTriplesMap> mappingList = obdaModel.generatePPMapping().getTripleMaps(); HashMap<String, Integer> mappingStat = new HashMap<String, Integer>(); for (SQLPPTriplesMap mapping : mappingList) { String mappingId = mapping.getId(); int triplesCount = 0; try { OBDASQLQuery sourceQuery = mapping.getSourceQuery(); int tuples = getTuplesCount(sourceQuery, source); ImmutableList<TargetAtom> targetQuery = mapping.getTargetAtoms(); int atoms = targetQuery.size(); triplesCount = tuples * atoms; } catch (Exception e) { triplesCount = -1; // fails to count log.error(e.getMessage()); } mappingStat.put(mappingId, triplesCount); } statistics.put(source.getSourceID().toString(), mappingStat); }
private int getTuplesCount(OBDASQLQuery query, OBDADataSource source) throws ClassNotFoundException, SQLException { Statement st = null; ResultSet rs = null; int count = -1; try { String sql = String.format("select COUNT(*) %s", getSelectionString(query)); Connection c = ConnectionTools.getConnection(source); st = c.createStatement(); rs = st.executeQuery(sql); count = 0; while (rs.next()) { count = rs.getInt(1); } } catch (SQLException e) { throw e; } finally { try { rs.close(); } catch (Exception e) { // NO-OP } try { st.close(); } catch (Exception e) { // NO-OP } } return count; }
@Override public void initialise() throws Exception { editorKit = (OWLEditorKit)getEditorKit(); obdaModel = ((OBDAModelManager)editorKit.get(SQLPPMappingImpl.class.getName())).getActiveOBDAModel(); statistics = new VirtualABoxStatistics(obdaModel); }
public void run() { OBDAProgressMonitor monitor = new OBDAProgressMonitor("Create statistics...", getWorkspace()); monitor.addProgressListener(pnlStatistics); monitor.start(); // refresh the statistics every time users click the menu. statistics.refresh(); pnlStatistics.initContent(statistics); monitor.stop(); if(!pnlStatistics.isCancelled() && !pnlStatistics.isErrorShown()) { dialog.setVisible(true); } } };
/** * Returns one triple count from a particular mapping. * * @param datasourceId * The data source identifier. * @param mappingId * The mapping identifier. * @return The number of triples. */ public int getStatistics(String datasourceId, String mappingId) { final HashMap<String, Integer> mappingStat = getStatistics(datasourceId); int triplesCount = mappingStat.get(mappingId).intValue(); return triplesCount; }
public void refresh() { final List<OBDADataSource> sourceList = model.getSources(); for (OBDADataSource database : sourceList) { URI sourceUri = database.getSourceID(); List<OBDAMappingAxiom> mappingList = model.getMappings(sourceUri); HashMap<String, Integer> mappingStat = new HashMap<String, Integer>(); for (OBDAMappingAxiom mapping : mappingList) { String mappingId = mapping.getId(); int triplesCount = 0; try { OBDASQLQuery sourceQuery = mapping.getSourceQuery(); int tuples = getTuplesCount(database, sourceQuery); List<Function> targetQuery = mapping.getTargetQuery(); int atoms = targetQuery.size(); triplesCount = tuples * atoms; } catch (Exception e) { triplesCount = -1; // fails to count log.error(e.getMessage()); } mappingStat.put(mappingId, triplesCount); } String sourceId = sourceUri.toString(); statistics.put(sourceId, mappingStat); } }
private int getTuplesCount(OBDADataSource sourceId, OBDASQLQuery query) throws NoDatasourceSelectedException, ClassNotFoundException, SQLException { Statement st = null; ResultSet rs = null; int count = -1; try { String sql = String.format("select COUNT(*) %s", getSelectionString(query)); Connection c = conn.getConnection(sourceId); st = c.createStatement(); rs = st.executeQuery(sql); count = 0; while (rs.next()) { count = rs.getInt(1); } } catch (SQLException e) { throw e; } finally { try { rs.close(); } catch (Exception e) { // NO-OP } try { st.close(); } catch (Exception e) { // NO-OP } } return count; }