List of usage examples for com.google.common.collect HashBasedTable create
public static <R, C, V> HashBasedTable<R, C, V> create()
From source file:com.intuit.wasabi.repository.impl.cassandra.CassandraExperimentRepository.java
/** * Get the experiments for an Application *///from www.ja va 2 s. co m @Override public Table<Experiment.ID, Experiment.Label, Experiment> getExperimentList(Application.Name appName) { Rows<Experiment.ID, String> rows = getExperimentRows(appName); Table<Experiment.ID, Experiment.Label, Experiment> result = HashBasedTable.create(); if (!rows.isEmpty()) { for (int i = 0; i < rows.size(); i++) { ColumnList<String> columns = rows.getRowByIndex(i).getColumns(); Experiment experiment = new CassandraExperiment(columns); if (experiment.getState() != State.TERMINATED && experiment.getState() != State.DELETED) { result.put(experiment.getID(), experiment.getLabel(), experiment); } } } return result; }
From source file:carskit.data.processor.DataDAO.java
public librec.data.SparseMatrix toTraditionalSparseMatrix(SparseMatrix sm) { Table<Integer, Integer, Double> dataTable = HashBasedTable.create(); Multimap<Integer, Integer> colMap = HashMultimap.create(); for (int uiid : sm.rows()) { int uid = getUserIdFromUI(uiid); int iid = getItemIdFromUI(uiid); SparseVector sv = sm.row(uiid);//from w w w.j a va 2s . co m if (sv.getCount() > 0) { dataTable.put(uid, iid, sv.mean()); colMap.put(iid, uid); } } return new librec.data.SparseMatrix(numUsers(), numItems(), dataTable, colMap); }
From source file:i5.las2peer.services.recommender.librec.rating.TimeComNeighSVD.java
@Override protected void buildModel() throws Exception { Logs.info("{}{} learn model parameters ...", new Object[] { algoName, foldInfo }); for (int iter = 1; iter <= numIters; iter++) { loss = 0;/*from w w w . ja v a 2s .co m*/ for (MatrixEntry me : trainMatrix) { int u = me.row(); int i = me.column(); double rui = me.get(); long timestamp = (long) timeMatrix.get(u, i); // day t int t = days(timestamp, minTrainTimestamp); int period = period(timestamp); int bin = bin(t); double dev_ut = dev(u, t); // set non community-related variables List<Integer> Iu = userItemsCache.get(u); double wi = Iu.size() > 0 ? Math.pow(Iu.size(), -0.5) : 0; // set community-related variables int cbin = cbin(t); List<Integer> itemCommunities = itemCommunitiesCache.get(cbin).get(i); List<Integer> userCommunities = userCommunitiesCache.get(cbin).get(u); List<Integer> userStaticCommunities = userCommunitiesCache.get(0).get(u); List<Integer> Icu = userCommunitiesItemsCache.get(cbin).get(u); double wc = Icu.size() > 0 ? Math.pow(Icu.size(), -0.5) : 0; // lazy initialization if (!But.contains(u, t)) But.put(u, t, Randoms.gaussian(initMean, initStd)); if (!Pukt.containsKey(u)) Pukt.put(u, HashBasedTable.create()); for (int k = 0; k < numFactors; k++) if (!Pukt.get(u).contains(k, t)) Pukt.get(u).put(k, t, Randoms.gaussian(initMean, initStd)); for (int c : userCommunities) { if (!BCut.get(cbin).contains(c, t)) BCut.get(cbin).put(c, t, Randoms.gaussian(initMean, initStd)); if (!OCut.get(cbin).containsKey(c)) OCut.get(cbin).put(c, HashBasedTable.create()); for (int k = 0; k < numFactors; k++) if (!OCut.get(cbin).get(c).contains(k, t)) OCut.get(cbin).get(c).put(k, t, Randoms.gaussian(initMean, initStd)); } double pui = predict(u, i); double eui = pui - rui; loss += eui * eui; // Update baseline parameters // ========================== double bi = itemBias.get(i); double cu = Cu.get(u); double cut = Cut.get(u, t); double bit = Bit.get(i, bin); double bipt = Bipt.get(i, period); double bu = userBias.get(u); double but = But.get(u, t); double bupt = Bupt.get(u, period); double au = Alpha.get(u); // update bi double sgd = eui * (cu + cut) + regB * bi; itemBias.add(i, -lRate * sgd); loss += regB * bi * bi; // update bi,bin(t) sgd = eui * (cu + cut) + regB * bit; Bit.add(i, bin, -lRate * sgd); loss += regB * bit * bit; // update bi,period(t) sgd = eui * (cu + cut) + regB * bipt; Bipt.add(i, period, -lRate * sgd); loss += regB * bipt * bipt; // update cu sgd = eui * (bi + bit + bipt) + regB * cu; Cu.add(u, -lRate * sgd); loss += regB * cu * cu; // update cut sgd = eui * (bi + bit + bipt) + regB * cut; Cut.add(u, t, -lRate * sgd); loss += regB * cut * cut; // update bu sgd = eui + regB * bu; userBias.add(u, -lRate * sgd); loss += regB * bu * bu; // update au sgd = eui * dev_ut + regB * au; Alpha.add(u, -lRate * sgd); loss += regB * au * au; // update but sgd = eui + regB * but; But.put(u, t, but - lRate * sgd); loss += regB * but * but; // update bu,period(t) sgd = eui + regB * bupt; Bupt.add(u, period, -lRate * sgd); loss += regB * bupt * bupt; // update bcu, bcut for (int c : userCommunities) { double bcu = BCu[cbin].get(c); double bcut = BCut.get(cbin).get(c, t); double muc = userMemberships[cbin].get(u, c); sgd = eui * muc + regC * bcu; BCu[cbin].add(c, -lRateC * sgd); loss += regC * bcu * bcu; sgd = eui * muc + regC * bcut; BCut.get(cbin).put(c, t, bcut - lRateC * sgd); loss += regC * bcut * bcut; } // update alpha_c for (int c : userStaticCommunities) { double alphac = AlphaC.get(c); double devct = devc(c, t); double muc = userMemberships[0].get(u, c); sgd = eui * devct * muc + regC * alphac; AlphaC.add(c, -lRateC * sgd); loss += regC * alphac * alphac; } // update bci, bcit for (int c : itemCommunities) { double bci = BCi[cbin].get(c); double bcit = BCit[cbin].get(c, bin); double mic = itemMemberships[cbin].get(i, c); sgd = eui * mic + regC * bci; BCi[cbin].add(c, -lRateC * sgd); loss += regC * bci * bci; sgd = eui * mic + regC * bcit; BCit[cbin].add(c, bin, -lRateC * sgd); loss += regC * bcit * bcit; } // Update SVD model parameters // =========================== Table<Integer, Integer, Double> Pkt = Pukt.get(u); for (int k = 0; k < numFactors; k++) { double qik = Q.get(i, k); double puk = P.get(u, k); double auk = Auk.get(u, k); double pkt = Pkt.get(k, t); double pukt = puk + auk * dev_ut + pkt; double sum_yk = 0; for (int j : Iu) sum_yk += Y.get(j, k); double sum_zk = 0; for (int j : Icu) sum_zk += Z.get(j, k); double sum_ocuk = 0; double sum_ocukt = 0; for (int c : userCommunities) { double muc = userMemberships[cbin].get(u, c); sum_ocuk += OCu[cbin].get(c, k) * muc; sum_ocukt += OCut.get(cbin).get(c).get(k, t) * muc; } double sum_acuk = 0; for (int c : userStaticCommunities) { double muc = userMemberships[0].get(u, c); sum_acuk += ACu.get(c, k) * devc(c, t) * muc; } double sum_ocik = 0; for (int c : itemCommunities) { double mic = itemMemberships[cbin].get(i, c); sum_ocik += OCi[cbin].get(c, k) * mic; } // update qik sgd = eui * (pukt + sum_ocuk + sum_ocukt + sum_acuk + wi * sum_yk + wc * sum_zk) + regI * qik; Q.add(i, k, -lRateF * sgd); loss += regI * qik * qik; // update puk sgd = eui * (qik + sum_ocik) + regU * puk; P.add(u, k, -lRateF * sgd); loss += regU * puk * puk; // update auk sgd = eui * (qik + sum_ocik) * dev_ut + regU * auk; Auk.add(u, k, -lRateF * sgd); loss += regU * auk * auk; // update pkt sgd = eui * (qik + sum_ocik) + regU * pkt; Pkt.put(k, t, pkt - lRateF * sgd); loss += regU * pkt * pkt; // update yjk for (int j : Iu) { double yjk = Y.get(j, k); sgd = eui * wi * (qik + sum_ocik) + regI * yjk; Y.add(j, k, -lRateF * sgd); loss += regI * yjk * yjk; } // update oci for (int c : itemCommunities) { double ocik = OCi[cbin].get(c, k); double mic = itemMemberships[cbin].get(i, c); sgd = eui * mic * (pukt + sum_ocuk + sum_ocukt + sum_acuk + wi * sum_yk + wc * sum_zk) + regCF * ocik; OCi[cbin].add(c, k, -lRateCF * sgd); loss += regCF * ocik * ocik; } // update ocu and ocut for (int c : userCommunities) { double ocuk = OCu[cbin].get(c, k); double ocukt = OCut.get(cbin).get(c).get(k, t); double muc = userMemberships[cbin].get(u, c); sgd = eui * muc * (qik + sum_ocik) + regCF * ocuk; OCu[cbin].add(c, k, -lRateCF * sgd); loss += regCF * ocuk * ocuk; sgd = eui * muc * (qik + sum_ocik) + regCF * ocukt; OCut.get(cbin).get(c).put(k, t, ocukt - lRateCF * sgd); loss += regCF * ocukt * ocukt; } // update acu for (int c : userStaticCommunities) { double acuk = ACu.get(c, k); double muc = userMemberships[0].get(u, c); double devcut = devc(c, t); sgd = eui * devcut * muc * (qik + sum_ocik) + regCF * acuk; ACu.add(c, k, -lRateCF * sgd); loss += regCF * acuk * acuk; } // update zjk for (int j : Icu) { double zjk = Z.get(j, k); sgd = eui * wc * (qik + sum_ocik) + regCF * zjk; Z.add(j, k, -lRateCF * sgd); loss += regCF * zjk * zjk; } } // Update neighborhood model parameters // ==================================== // update w, c and phi double sgd_phi = 0; for (int j : Iu) { double e = decay(u, j, t); double ruj = trainMatrix.get(u, j); double buj = buj(u, j, timestamp); buj += userBias.get(u) + Alpha.get(u) * dev_ut; buj += But.contains(u, t) ? But.get(u, t) : 0; // update w double wij = W.get(i, j); sgd = eui * wi * e * (ruj - buj) + regN * wij; W.add(i, j, -lRateN * sgd); loss += regI * wij * wij; // update c double cij = C.get(i, j); sgd = eui * wi * e + regN * cij; C.add(i, j, -lRateN * sgd); loss += regI * cij * cij; // update phi int diff = Math.abs(t - days((long) timeMatrix.get(u, j), minTrainTimestamp)); sgd_phi = eui * wi * (-1 * diff) * e * ((ruj - buj) * wij + cij); } double phi = Phi.get(u); sgd_phi += regN * phi; Phi.add(u, -lRateMu * sgd_phi); loss += regI * phi * phi; // update d and psi double sgd_psi = 0; for (int j : Icu) { double dij = D.get(i, j); double e = cdecay(u, j, t, cbin); sgd = eui * wc + e + regCN * dij; D.add(i, j, -lRateCN * sgd); loss += regCN * dij * dij; int tj = days((long) timeMatrix.get(u, j), minTrainTimestamp); int diff = Math.abs(t - tj); sgd_psi += eui * wc * (-1 * diff) * e * dij; } double psi = Psi.get(u); sgd_psi += regCN * psi; // do not let psi become negative double delta_psi = (lRateMu * sgd_psi > psi) ? (psi / 2.0) : (lRateMu * sgd_psi); Psi.add(u, -delta_psi); loss += regCN * psi * psi; } loss *= 0.5; if (isConverged(iter)) break; } }
From source file:com.intuit.wasabi.repository.cassandra.impl.CassandraExperimentRepository.java
/** * {@inheritDoc}/* w w w .ja v a 2 s. c om*/ */ @Override public Table<Experiment.ID, Experiment.Label, Experiment> getExperimentList(Application.Name appName) { try { List<com.intuit.wasabi.repository.cassandra.pojo.Experiment> experimentPojos = experimentAccessor .getExperimentByAppName(appName.toString()).all(); Table<Experiment.ID, Experiment.Label, Experiment> result = HashBasedTable.create(); for (com.intuit.wasabi.repository.cassandra.pojo.Experiment experimentPojo : experimentPojos) { Experiment experiment = ExperimentHelper.makeExperiment(experimentPojo); if (experiment.getState() != State.TERMINATED && experiment.getState() != State.DELETED) { result.put(experiment.getID(), experiment.getLabel(), experiment); } } return result; } catch (Exception e) { throw new RepositoryException( "Could not retrieve experiment list " + appName.toString() + "because: " + e, e); } }
From source file:org.ow2.authzforce.core.pdp.impl.policy.CoreRefPolicyProvider.java
/** * Creates an instance from policy locations * * @param policyURLs//from ww w . j a va 2 s. c o m * location of Policy(Set) elements (JAXB) to be parsed for future reference by Policy(Set)IdReferences * @param ignoreOldPolicyVersions * for any given policy ID, ignore all versions except the last one if there are multiple versions of the policy * @param xacmlParserFactory * XACML parser factory for parsing any XACML Policy(Set) * @param maxPolicySetRefDepth * maximum allowed depth of PolicySet reference chain (via PolicySetIdReference): PolicySet1 -> PolicySet2 -> ...; a strictly negative value means no limit * @param combiningAlgRegistry * registry of policy/rule combining algorithms * @param expressionFactory * Expression factory for parsing Expressions used in the policy(set) * @return instance of this class * @throws java.lang.IllegalArgumentException * if {@code policyURLs == null || policyURLs.length == 0 || xacmlParserFactory == null || expressionFactory == null || combiningAlgRegistry == null}; or one of {@code policyURLs} is * null or is not a valid XACML Policy(Set) or conflicts with another because it has same Policy(Set)Id and Version. Beware that the Policy(Set)Issuer is ignored from this check! */ public static CoreRefPolicyProvider getInstance(final Collection<URL> policyURLs, final boolean ignoreOldPolicyVersions, final XmlnsFilteringParserFactory xacmlParserFactory, final int maxPolicySetRefDepth, final ExpressionFactory expressionFactory, final CombiningAlgRegistry combiningAlgRegistry) throws IllegalArgumentException { if (policyURLs == null || policyURLs.isEmpty()) { throw ILLEGAL_POLICY_URLS_ARGUMENT_EXCEPTION; } if (xacmlParserFactory == null) { throw ILLEGAL_XACML_PARSER_FACTORY_ARGUMENT_EXCEPTION; } if (expressionFactory == null) { throw ILLEGAL_EXPRESSION_FACTORY_ARGUMENT_EXCEPTION; } if (combiningAlgRegistry == null) { throw ILLEGAL_COMBINING_ALG_REGISTRY_ARGUMENT_EXCEPTION; } final XmlnsFilteringParser xacmlParser; try { xacmlParser = xacmlParserFactory.getInstance(); } catch (final JAXBException e) { throw new IllegalArgumentException("Failed to create JAXB unmarshaller for XML Policy(Set)", e); } final Table<String, PolicyVersion, StaticTopLevelPolicyElementEvaluator> updatablePolicyTable = HashBasedTable .create(); final Table<String, PolicyVersion, PolicyWithNamespaces<PolicySet>> updatablePolicySetTable = HashBasedTable .create(); int policyUrlIndex = 0; for (final URL policyURL : policyURLs) { if (policyURL == null) { throw new IllegalArgumentException("policyURL #" + policyUrlIndex + " undefined"); } final Object jaxbPolicyOrPolicySetObj; try { jaxbPolicyOrPolicySetObj = xacmlParser.parse(policyURL); } catch (final JAXBException e) { throw new IllegalArgumentException( "Failed to unmarshall Policy(Set) XML document from policy location: " + policyURL, e); } final Map<String, String> nsPrefixUriMap = xacmlParser.getNamespacePrefixUriMap(); if (jaxbPolicyOrPolicySetObj instanceof Policy) { final Policy jaxbPolicy = (Policy) jaxbPolicyOrPolicySetObj; final String policyId = jaxbPolicy.getPolicyId(); final String policyVersionStr = jaxbPolicy.getVersion(); final PolicyVersion policyVersion = new PolicyVersion(policyVersionStr); if (ignoreOldPolicyVersions) { final Map<PolicyVersion, StaticTopLevelPolicyElementEvaluator> policyVersions = updatablePolicyTable .row(policyId); if (policyVersions != null) { final boolean isOld = policyVersions.keySet().parallelStream() .anyMatch(v -> policyVersion.compareTo(v) <= 0); if (isOld) { // skip continue; } /* * Else replace/overwrite with this new version (make sure it is the only one), so empty the row first */ policyVersions.clear(); } } final StaticTopLevelPolicyElementEvaluator policyEvaluator; try { policyEvaluator = PolicyEvaluators.getInstance(jaxbPolicy, null, nsPrefixUriMap, expressionFactory, combiningAlgRegistry); } catch (final IllegalArgumentException e) { throw new IllegalArgumentException( "Invalid Policy with PolicyId=" + policyId + ", Version=" + policyVersionStr, e); } final StaticTopLevelPolicyElementEvaluator previousValue = updatablePolicyTable.put(policyId, policyVersion, policyEvaluator); if (previousValue != null) { throw new IllegalArgumentException("Policy conflict: two policies with same PolicyId=" + policyId + ", Version=" + policyVersionStr); } } else if (jaxbPolicyOrPolicySetObj instanceof PolicySet) { final PolicySet jaxbPolicySet = (PolicySet) jaxbPolicyOrPolicySetObj; final String policyId = jaxbPolicySet.getPolicySetId(); final String policyVersionStr = jaxbPolicySet.getVersion(); final PolicyVersion policyVersion = new PolicyVersion(policyVersionStr); if (ignoreOldPolicyVersions) { final Map<PolicyVersion, PolicyWithNamespaces<PolicySet>> policyVersions = updatablePolicySetTable .row(policyId); if (policyVersions != null) { final boolean isOld = policyVersions.keySet().parallelStream() .anyMatch(v -> policyVersion.compareTo(v) <= 0); if (isOld) { // skip continue; } /* * Else replace/overwrite with this new version (make sure it is the only one), so empty the row first */ policyVersions.clear(); } } final PolicyWithNamespaces<PolicySet> previousValue = updatablePolicySetTable.put(policyId, policyVersion, new PolicyWithNamespaces<>(jaxbPolicySet, nsPrefixUriMap)); if (previousValue != null) { throw new IllegalArgumentException("Policy conflict: two PolicySets with same PolicySetId=" + policyId + ", Version=" + policyVersionStr); } /* * PolicySets cannot be parsed before we have collected them all, because each PolicySet may refer to others via PolicySetIdReferences */ } else { throw new IllegalArgumentException("Unexpected element found as root of the policy document: " + jaxbPolicyOrPolicySetObj.getClass().getSimpleName()); } policyUrlIndex++; } final PolicyMap<StaticTopLevelPolicyElementEvaluator> policyMap = new PolicyMap<>( updatablePolicyTable.rowMap()); final PolicyMap<PolicyWithNamespaces<PolicySet>> policySetMap = new PolicyMap<>( updatablePolicySetTable.rowMap()); return new CoreRefPolicyProvider(policyMap, policySetMap, maxPolicySetRefDepth, expressionFactory, combiningAlgRegistry); }
From source file:structure.matrix.SparseMatrix.java
public static SparseMatrix readMatrix(String filePath) throws IOException { // Table {row-id, col-id, rate} Table<Integer, Integer, Double> dataTable = HashBasedTable.create(); // Map {col-id, multiple row-id}: used to fast build a rating matrix Multimap<Integer, Integer> colMap = HashMultimap.create(); BufferedReader br = FileIO.getReader(filePath); br.readLine();//from ww w. j a va 2 s . c om String line = br.readLine(); String[] terms = line.trim().split("[ \t,]+"); int Nu = Integer.parseInt(terms[0]); int Nv = Integer.parseInt(terms[1]); while ((line = br.readLine()) != null) { String[] data = line.trim().split("[ \t,]+"); int user = Integer.parseInt(data[0]) - 1; int item = Integer.parseInt(data[1]) - 1; Double rate = Double.parseDouble(data[2]); dataTable.put(user, item, rate); colMap.put(item, user); } br.close(); // build rating matrix SparseMatrix mat = new SparseMatrix(Nu, Nv, dataTable, colMap); dataTable = null; return mat; }
From source file:structure.matrix.SparseMatrix.java
public SparseMatrix selectColumn(int[] column) { Table<Integer, Integer, Double> dataTable = HashBasedTable.create(); Multimap<Integer, Integer> colMap = HashMultimap.create(); int s = 0;/*from ww w . jav a2 s . com*/ for (int c : column) { int start = colPtr[c], end = colPtr[c + 1]; int len = end - start; for (int r = 0; r < len; r++) { int j = start + r; dataTable.put(rowInd[j], s, colData[j]); colMap.put(s, rowInd[j]); } s++; } SparseMatrix sub = new SparseMatrix(numRows, s, dataTable, colMap); return sub; }
From source file:paquete.AnalizadorSemantico.java
public Relacion Menor(NodoBase ni, NodoBase nd, Relacion relacion) { Table<Integer, String, Object> relacionTemporal = HashBasedTable.create(); int j = 0;/*from www . j a v a 2 s .co m*/ if (checkTipos(ni, nd, relacion.getAtributos(), relacion.getTipos())) { if (ni instanceof NodoAtributo && nd instanceof NodoAtributo) { if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof Double) { for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) { if ((Double) relacion.getDatos().get(i, ni.getToken().getValor()) < (Double) (relacion .getDatos().get(i, nd.getToken().getValor()))) { for (int col = 0; col < relacion.getAtributos().length; col++) { relacionTemporal.put(j, relacion.getAtributos()[col], relacion.getDatos().get(i, relacion.getAtributos()[col])); } j++; } } } if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof Date) { for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) { if (((Date) relacion.getDatos().get(i, ni.getToken().getValor())) .before((Date) (relacion.getDatos().get(i, nd.getToken().getValor())))) { for (int col = 0; col < relacion.getAtributos().length; col++) { relacionTemporal.put(j, relacion.getAtributos()[col], relacion.getDatos().get(i, relacion.getAtributos()[col])); } j++; } } } if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof String) { for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) { if (((String) relacion.getDatos().get(i, ni.getToken().getValor())) .compareTo((String) (relacion.getDatos().get(i, nd.getToken().getValor()))) < 0) { for (int col = 0; col < relacion.getAtributos().length; col++) { relacionTemporal.put(j, relacion.getAtributos()[col], relacion.getDatos().get(i, relacion.getAtributos()[col])); } j++; } } } } else { for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) { double temp; String tempS = nd.getToken().getValor(); Date tempD = null; if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Double) { temp = Double.parseDouble(nd.getToken().getValor()); if ((Double) relacion.getDatos().get(i, ni.getToken().getValor()) < (temp)) { for (int a = 0; a < relacion.getAtributos().length; a++) { relacionTemporal.put(j, relacion.getAtributos()[a], relacion.getDatos().get(i, relacion.getAtributos()[a])); } j++; } } else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String) if (((String) relacion.getDatos().get(i, ni.getToken().getValor())).compareTo(tempS) < 0) { for (int a = 0; a < relacion.getAtributos().length; a++) { relacionTemporal.put(j, relacion.getAtributos()[a], relacion.getDatos().get(i, relacion.getAtributos()[a])); } j++; } else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Date) { DateFormat df = new SimpleDateFormat("dd/mm/yyyy"); try { tempD = df.parse(nd.getToken().getValor()); } catch (ParseException ex) { Logger.getLogger(AnalizadorSemantico.class.getName()).log(Level.SEVERE, null, ex); } if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String) if (((Date) relacion.getDatos().get(i, ni.getToken().getValor())).before(tempD)) { for (int a = 0; a < relacion.getAtributos().length; a++) { relacionTemporal.put(j, relacion.getAtributos()[a], relacion.getDatos().get(i, relacion.getAtributos()[a])); } j++; } } } } } if (!relacionTemporal.isEmpty()) return new Relacion("", relacion.getAtributos(), relacion.getTipos(), relacionTemporal); else return null; }
From source file:com.inmobi.conduit.AbstractService.java
protected Table<String, Long, Long> parseCountersFile(FileSystem fs) { List<Path> partFiles = listPartFiles(tmpCounterOutputPath, fs); if (partFiles == null || partFiles.size() == 0) { LOG.warn("No counters files generated by mapred job"); return null; }// w w w .jav a 2 s .c o m Table<String, Long, Long> result = HashBasedTable.create(); for (Path filePath : partFiles) { FSDataInputStream fin = null; Scanner scanner = null; try { fin = fs.open(filePath); scanner = new Scanner(fin); while (scanner.hasNext()) { String counterNameValue = null; try { counterNameValue = scanner.next(); String tmp[] = counterNameValue.split(ConduitConstants.AUDIT_COUNTER_NAME_DELIMITER); if (tmp.length < 4) { LOG.error("Malformed counter name,skipping " + counterNameValue); continue; } String streamFileNameCombo = tmp[0] + ConduitConstants.AUDIT_COUNTER_NAME_DELIMITER + tmp[1]; Long publishTimeWindow = Long.parseLong(tmp[2]); Long numOfMsgs = Long.parseLong(tmp[3]); result.put(streamFileNameCombo, publishTimeWindow, numOfMsgs); } catch (Exception e) { LOG.error("Counters file has malformed line with counter name = " + counterNameValue + " ..skipping the line", e); } } } catch (IOException e1) { LOG.error("Error while opening file " + filePath + " Skipping"); continue; } finally { try { if (fin != null) { fin.close(); } if (scanner != null) { scanner.close(); } } catch (Exception e) { LOG.warn("Error while closing file " + filePath + " or scanner"); } } } return result; }
From source file:paquete.AnalizadorSemantico.java
public Relacion MenorIgual(NodoBase ni, NodoBase nd, Relacion relacion) { Table<Integer, String, Object> relacionTemporal = HashBasedTable.create(); int j = 0;//from www .j a va2 s .c om if (checkTipos(ni, nd, relacion.getAtributos(), relacion.getTipos())) { if (ni instanceof NodoAtributo && nd instanceof NodoAtributo) { if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof Double) { for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) { if ((Double) relacion.getDatos().get(i, ni.getToken().getValor()) <= (Double) (relacion .getDatos().get(i, nd.getToken().getValor()))) { for (int col = 0; col < relacion.getAtributos().length; col++) { relacionTemporal.put(j, relacion.getAtributos()[col], relacion.getDatos().get(i, relacion.getAtributos()[col])); } j++; } } } if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof Date) { for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) { if (((Date) relacion.getDatos().get(i, ni.getToken().getValor())) .before((Date) (relacion.getDatos().get(i, nd.getToken().getValor()))) || ((Date) relacion.getDatos().get(i, ni.getToken().getValor())) .equals((Date) (relacion.getDatos().get(i, nd.getToken().getValor())))) { for (int col = 0; col < relacion.getAtributos().length; col++) { relacionTemporal.put(j, relacion.getAtributos()[col], relacion.getDatos().get(i, relacion.getAtributos()[col])); } j++; } } } if (relacion.getDatos().column(ni.getToken().getValor()).get(0) instanceof String) { for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) { if (((String) relacion.getDatos().get(i, ni.getToken().getValor())) .compareTo((String) (relacion.getDatos().get(i, nd.getToken().getValor()))) <= 0) { for (int col = 0; col < relacion.getAtributos().length; col++) { relacionTemporal.put(j, relacion.getAtributos()[col], relacion.getDatos().get(i, relacion.getAtributos()[col])); } j++; } } } } else { for (int i = 0; i < relacion.getDatos().size() / relacion.getAtributos().length; i++) { double temp; String tempS = nd.getToken().getValor(); Date tempD = null; if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Double) { temp = Double.parseDouble(nd.getToken().getValor()); if ((Double) relacion.getDatos().get(i, ni.getToken().getValor()) <= (temp)) { for (int a = 0; a < relacion.getAtributos().length; a++) { relacionTemporal.put(j, relacion.getAtributos()[a], relacion.getDatos().get(i, relacion.getAtributos()[a])); } j++; } } else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String) if (((String) relacion.getDatos().get(i, ni.getToken().getValor())).compareTo(tempS) <= 0) { for (int a = 0; a < relacion.getAtributos().length; a++) { relacionTemporal.put(j, relacion.getAtributos()[a], relacion.getDatos().get(i, relacion.getAtributos()[a])); } j++; } else if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof Date) { DateFormat df = new SimpleDateFormat("dd/mm/yyyy"); try { tempD = df.parse(nd.getToken().getValor()); } catch (ParseException ex) { Logger.getLogger(AnalizadorSemantico.class.getName()).log(Level.SEVERE, null, ex); } if (relacion.getDatos().get(i, ni.getToken().getValor()) instanceof String) if (((Date) relacion.getDatos().get(i, ni.getToken().getValor())).before(tempD) || ((Date) relacion.getDatos().get(i, ni.getToken().getValor())) .equals(tempD)) { for (int a = 0; a < relacion.getAtributos().length; a++) { relacionTemporal.put(j, relacion.getAtributos()[a], relacion.getDatos().get(i, relacion.getAtributos()[a])); } j++; } } } } } if (!relacionTemporal.isEmpty()) return new Relacion("", relacion.getAtributos(), relacion.getTipos(), relacionTemporal); else return null; }