Advertisement
jbjares

Untitled

Mar 28th, 2015
487
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.72 KB | None | 0 0
  1.     @Test(groups= { "default" },priority=8,enabled=true)
  2.     public void testPreparedQueryCacheGeneration3DFromVirtuosoToMongoDB_50() throws Exception{
  3.         String projectName = "projectTest";
  4.         String simulationName = "simulationUnitTest";
  5.         System.out.println("STARTING 50");
  6.         JenaModel model = new JenaModel();
  7.  
  8.         String query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> "
  9.                 + "PREFIX owl: <http://www.w3.org/2002/07/owl#> "
  10.                 + "PREFIX xsd: <http://www.w3.org/2001/XMLSchema#> "
  11.                 + "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> "
  12.                 + "PREFIX fem: <http://www.sifemontologies.com/ontologies/FiniteElementModel.owl#> "
  13.                 + "PREFIX pak: <http://www.sifemontologies.com/ontologies/FEMSettingsPAK.owl#> "
  14.                 + "PREFIX sim: <http://www.sifemontologies.com/ontologies/Simulation.owl#> "
  15.                 + "SELECT ?material ?materialType ?node ?xCoord ?yCoord ?zCoord ?translationX ?translationY ?translationZ ?subDomain ?id  "
  16.                 + "FROM NAMED <http://www.sifemontologies.com/ontologies/displacement_50>  "
  17.                 + "WHERE {  "
  18.                 + "GRAPH ?g {  "
  19.                 + "?material rdf:type fem:Material . ?material fem:hasMaterialNumber ?y .    ?material pak:hasMaterialSettings ?z .  ?z pak:MATTYPE ?materialType. FILTER (?y=1) . ?node rdf:type fem:Node .   "
  20.                 + "?node fem:isNodeOf ?subDomain. ?node fem:hasNodeID ?id. ?subDomain fem:makesUp ?subDomainGroup. ?subDomainGroup fem:hasMaterial ?material. ?node fem:hasXCoordinate ?xCoord . ?node fem:hasYCoordinate ?yCoord . ?node fem:hasZCoordinate ?zCoord . ?node fem:holdsValueFor ?b . ?b rdf:type fem:Translation. ?b sim:hasVectorValue ?a . ?a sim:isReal true . ?a sim:hasVectorXValue ?translationX . ?a sim:hasVectorYValue ?translationY . ?a sim:hasVectorZValue ?translationZ .  "
  21.                 + "} "
  22.                 + " }";
  23.        
  24.         List<String> queryVariables = new ArrayList<String>();
  25.  
  26.         ResultSet results = Util.executeQuery(query, virtDataset);
  27.        
  28.         queryVariables.add("material");queryVariables.add("materialType");queryVariables.add("node");
  29.         queryVariables.add("xCoord");queryVariables.add("yCoord");queryVariables.add("zCoord");
  30.         queryVariables.add("translationX");queryVariables.add("translationY");queryVariables.add("translationZ");
  31.         queryVariables.add("subDomain");queryVariables.add("id");
  32.  
  33.          Map<String, List<RDFNode>> queryModel = model.queryModelWithResultService(results,queryVariables);
  34.  
  35.         //List<RDFNode> materials = queryModel.get(queryVariables.get(0));
  36.         //List<RDFNode> materialTypes = queryModel.get(queryVariables.get(1));     
  37.         List<String> nodes = new Util().changeFromRDFNodeToStringList(queryModel.get(queryVariables.get(2)));
  38.         List<String> xCoords = new Util().changeFromRDFNodeToStringList(queryModel.get(queryVariables.get(3)));
  39.         //List<RDFNode> yCoords = queryModel.get(queryVariables.get(4));
  40.         List<String> zCoords = new Util().changeFromRDFNodeToStringList(queryModel.get(queryVariables.get(5)));
  41.         List<String> translationXs = new Util().changeFromRDFNodeToStringList(queryModel.get(queryVariables.get(6)));
  42.         //List<RDFNode> translationYs = queryModel.get(queryVariables.get(7));
  43.         //List<String> translationZs = new Util().changeFromRDFNodeToStringList(queryModel.get(queryVariables.get(8)));
  44.         List<String> subDomains = new Util().changeFromRDFNodeToStringList(queryModel.get(queryVariables.get(9)));
  45.         List<String> ids = new Util().changeFromRDFNodeToStringList(queryModel.get(queryVariables.get(10)));
  46.  
  47.         System.out.println("Nodes number: " + nodes.size());
  48.  
  49.         //Assert.assertEquals(""+nodes.size()+"".trim(),"9600".trim());
  50.  
  51.  
  52. //      List<String> nodes = Collections.EMPTY_LIST;
  53. //      List<String> xCoords = Collections.EMPTY_LIST;
  54. //      List<String> translationXs = Collections.EMPTY_LIST;
  55. //      List<String> subDomains = Collections.EMPTY_LIST;
  56. //      List<String> ids = Collections.EMPTY_LIST;
  57. //     
  58.         if(nodes.toString().contains("[")){
  59.             String nodesStr = new Util().removeListKeysFromString(nodes.toString().replace(" ",""));
  60.             nodes = Arrays.asList(nodesStr.split(","));
  61.            
  62.             String xCoordStr = new Util().removeListKeysFromString(xCoords.toString().replace(" ",""));
  63.             xCoords = Arrays.asList(xCoordStr.split(","));
  64.            
  65.             String translationXStr = new Util().removeListKeysFromString(translationXs.toString().replace(" ",""));
  66.             translationXs = Arrays.asList(translationXStr.split(","));
  67.            
  68.             String zCoordsStr = new Util().removeListKeysFromString(zCoords.toString().replace(" ",""));
  69.             zCoords = Arrays.asList(zCoordsStr.split(","));
  70.            
  71.             String subDomainStr = new Util().removeListKeysFromString(subDomains.toString().replace(" ",""));
  72.             subDomains = Arrays.asList(subDomainStr.split(","));
  73.            
  74.             String idsStr = new Util().removeListKeysFromString(ids.toString().replace(" ",""));
  75.             ids = Arrays.asList(idsStr.split(","));
  76.         }
  77.        
  78.         int size = subDomains.size();
  79.         Map<String, Double> nodeXDisplacement = new HashMap<String, Double>();
  80.         Map<String, Double> nodeZCoord = new HashMap<String, Double>();
  81.         Map<Integer, String> idNodeMap = new HashMap<Integer, String>();
  82.         Map<String, Double> nodeXCoord = new HashMap<String, Double>();
  83.         System.out.println("size: "+size);
  84.         for(int i=0; i<size; i++){     
  85.             String displacementXStr = new Util().fixNumericValueForCacheList(translationXs.get(i));
  86.             String currentZCoordStr = new Util().fixNumericValueForCacheList(zCoords.get(i));
  87.             String currentXCoordStr = new Util().fixNumericValueForCacheList(xCoords.get(i));
  88.             String idStr = new Util().fixNumericValueForCacheList(ids.get(i));
  89.             if(displacementXStr==null || currentXCoordStr==null || idStr==null || currentZCoordStr==null){
  90.                 continue;
  91.             }
  92.             Double displacementX =  new Double(displacementXStr);
  93.             Double currentZCoord = new Double(currentZCoordStr);
  94.             Double currentXCoord = new Double(currentXCoordStr);
  95.             String node = nodes.get(i);
  96.             int nodeNumber = new Integer(idStr);
  97.             nodeXDisplacement.put(node, displacementX);
  98.             nodeZCoord.put(node, currentZCoord);
  99.             nodeXCoord.put(node, currentXCoord);
  100.             idNodeMap.put(nodeNumber, node);
  101.         }
  102.        
  103.         System.out.println("Final Nodes Remaining: " + idNodeMap.size());
  104.         //Assert.assertEquals(""+idNodeMap.size()+"".trim(),"2020".trim());
  105.        
  106.         List<String> datax = new ArrayList<String>();
  107.         List<String> datay = new ArrayList<String>();
  108.         List<String> dataz = new ArrayList<String>();
  109.         List<Integer> nodeSortedIds = new ArrayList<Integer>();
  110.         for(int i : idNodeMap.keySet()) {
  111.             nodeSortedIds.add(i);          
  112.         }
  113.         Collections.sort(nodeSortedIds);
  114.         Double previousXCoord = new Double(Float.MIN_VALUE);       
  115.         for(Integer id : nodeSortedIds){
  116.             String node = idNodeMap.get(id);
  117.             Double displacement = nodeXDisplacement.get(node);
  118.             Double currentXCoord = nodeXCoord.get(node);
  119.             Double currentZCoord = nodeZCoord.get(node);
  120.             if(currentXCoord > previousXCoord){
  121.                 datax.add(currentXCoord.toString());
  122.                 datay.add(displacement.toString());
  123.                 dataz.add(currentZCoord.toString());
  124.                 previousXCoord = currentXCoord;            
  125.             }
  126.         }
  127.        
  128.         ViewTO viewTO = new ViewTO();
  129.         for (String value : datax) {
  130.             viewTO.getxView().add(value);
  131.         }
  132.         for (String value : datay) {
  133.             viewTO.getyView().add(value);
  134.         }
  135.         for (String value : dataz) {
  136.             viewTO.getzView().add(value);
  137.         }
  138.                
  139.  
  140.         DataSetHashCacheTO greenwoodCache = new DataSetHashCacheTO();
  141.         greenwoodCache.setProjectName(projectName.toUpperCase());
  142.         greenwoodCache.setSimulationName(simulationName.toUpperCase());
  143.         greenwoodCache.setxName("BasilarMembraneMagnitude".toUpperCase());
  144.         greenwoodCache.setyName("DistanceFromTheCochleaBasis".toUpperCase());
  145.         greenwoodCache.setyName("ZValueForDisplacement".toUpperCase());
  146.         greenwoodCache.setHash(Util.generateHashCacheID(greenwoodCache));
  147.         greenwoodCache.setViewTO(viewTO);
  148.         greenwoodCache.setFrequency("50");
  149.         dataSetHashCacheDAO.insert(greenwoodCache);
  150.         System.out.println("DONE!");
  151.        
  152.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement