Changeset 18147
- Timestamp:
- 2008-12-08T17:08:06+13:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
other-projects/trunk/greenstone3-extension/mat/src/org/greenstone/gsdl3_extension/mat/DataMaker.java
r18093 r18147 554 554 return row; 555 555 } 556 556 557 /** 558 * This method will use Arrays.sort for sorting Map 559 * @param map 560 * @return outputList of Map.Entries 561 */ 562 557 563 public ArrayList sortMap(Map map) { 558 564 ArrayList outputList = null; … … 560 566 Set set = null; 561 567 Map.Entry[] entries = null; 568 // Logic: 569 // get a set from Map 570 // Build a Map.Entry[] from set 571 // Sort the list using Arrays.sort 572 // Add the sorted Map.Entries into arrayList and return 562 573 563 574 set = (Set) map.entrySet(); … … 568 579 } 569 580 581 // Sort the entries with your own comparator for the values: 570 582 Arrays.sort(entries, new Comparator() { 571 583 public int compareTo(Object lhs, Object rhs) { … … 587 599 } 588 600 return outputList; 589 } 601 }//End of sortMap 590 602 591 603 private Double div(Double d1, Double d2){ … … 596 608 597 609 private Double mul(Double d1,Double d2){ 598 BigDecimal b1 = new BigDecimal(d1.toString()); 610 //System.out.println(d1); 611 BigDecimal b1 = new BigDecimal(d1.toString()); 599 612 BigDecimal b2 = new BigDecimal(d2.toString()); 600 613 return new Double(b1.multiply(b2).doubleValue()); … … 627 640 } 628 641 } 629 630 double x = (double)totalElementUsed/totalElement; 631 Double d1 = new Double(x); 632 Double d2 = new Double(100); 642 //System.out.println(totalElementUsed +" "+ totalElement); 643 double x = (double)totalElementUsed/totalElement; 644 //System.out.println(x); 645 Double d1 = new Double(x); 646 //System.out.println(d1); 647 Double d2 = new Double(100); 633 648 Double result = mul(d1,d2); 634 649 return round(result.doubleValue(),1); … … 750 765 751 766 public HashMap getLinks(String[] args, String core_element){ 752 753 754 755 756 757 758 767 Element rootElement = getRootNode(core_element); 768 HashMap hp = new HashMap(); 769 NodeList listOfDocument = rootElement.getElementsByTagName("Document"); 770 ArrayList tempList = new ArrayList(); 771 772 773 for(int i = 0; i<args.length; i++){ 759 774 tempList.add(args[i]); 760 761 762 775 } 776 777 for(int s=0; s<listOfDocument.getLength() ; s++){ 763 778 Node docNode = listOfDocument.item(s); 764 779 Element docElement = (Element)docNode; … … 766 781 767 782 if(valueList.getLength()==1){ 768 String id = docNode.getAttributes().item(0).getNodeValue(); 769 Element valueElement = (Element)valueList.item(0); 770 NodeList textFNList = valueElement.getChildNodes(); 771 String text = ((Node)textFNList.item(0)).getNodeValue(); 772 773 if(tempList.contains(text)){ 774 hp.put(id, text); 775 } 783 String id = docNode.getAttributes().item(0).getNodeValue(); 784 785 Element valueElement = (Element)valueList.item(0); 786 NodeList textFNList = valueElement.getChildNodes(); 787 String text = ((Node)textFNList.item(0)).getNodeValue(); 788 789 if(tempList.contains(text)){ 790 hp.put(id, text); 791 } 776 792 } 777 778 779 780 781 782 783 793 } 794 795 rootElement = getRootNode(urlFile); 796 listOfDocument = rootElement.getElementsByTagName(documentTag); 797 HashMap newHp = new HashMap(); 798 799 for(int a=0; a<listOfDocument.getLength(); a++){ 784 800 Node docNode = listOfDocument.item(a); 785 801 Element docElement = (Element)docNode; … … 787 803 788 804 if(valueList.getLength()==1){ 789 String id = docNode.getAttributes().item(0).getNodeValue(); 790 Element valueElement = (Element)valueList.item(0); 791 NodeList textFNList = valueElement.getChildNodes(); 792 String text = ((Node)textFNList.item(0)).getNodeValue(); 793 newHp.put(text,id); 805 String id = docNode.getAttributes().item(0).getNodeValue(); 806 807 Element valueElement = (Element)valueList.item(0); 808 NodeList textFNList = valueElement.getChildNodes(); 809 String text = ((Node)textFNList.item(0)).getNodeValue(); 810 newHp.put(text,id); 794 811 } 795 } 796 797 HashMap tempMap = new HashMap(); 798 Collection c = hp.values(); 799 Iterator i = c.iterator(); 800 801 while(i.hasNext()){ 812 } 813 814 HashMap tempMap = new HashMap(); 815 Collection c = hp.values(); 816 Iterator i = c.iterator(); 817 while(i.hasNext()){ 802 818 String id = (String)i.next(); 803 819 if(newHp.containsKey(id)){ 804 805 if(text.contains("http")){806 tempMap.put((String)tempMap.get(id),text);807 820 String text = (String)newHp.get(id); 821 if(text.indexOf("http")!=-1){ 822 tempMap.put((String)tempMap.get(id),text); 823 } 808 824 } 809 810 811 812 } 813 825 } 826 827 return tempMap; 828 } 829 814 830 815 831 public ArrayList getURLMap(String elementName){ … … 820 836 821 837 if(rootElement.equals(null)){ 822 838 return new ArrayList(); 823 839 } 824 840 … … 827 843 if(listOfDocument.getLength()==0){return new ArrayList();} 828 844 829 for(int a=0; a<listOfDocument.getLength(); a++){ 845 //System.out.println(listOfDocument.getLength()); 846 for(int a=0; a<listOfDocument.getLength(); a++){ 830 847 Node docNode = listOfDocument.item(a); 831 848 Element docElement = (Element)docNode; 832 849 NodeList valueList = docElement.getElementsByTagName(valueTag); 833 850 834 for(int b=0; b<valueList.getLength(); b++){ 851 //System.out.println(valueList.getLength()); 852 for(int b=0; b<valueList.getLength(); b++){ 835 853 Element valueElement = (Element)valueList.item(b); 836 854 NodeList textFNList = valueElement.getChildNodes(); … … 838 856 839 857 if(!text.equals(" ")){ 840 841 842 843 844 845 alist.add(DocID);846 858 NamedNodeMap NodeIDMap = docNode .getAttributes(); 859 Node DocNodeID = NodeIDMap.item(0); 860 String DocID = DocNodeID.getNodeValue(); 861 if(alist.contains(DocID)){} 862 else{ 863 alist.add(DocID); 864 } 847 865 } 848 866 } 849 } 850 return alist; 851 } 867 } 868 869 return alist; 870 } 852 871 853 872 public HashMap getIdentifierLink(String core_element){ … … 882 901 } 883 902 } 884 } 885 return hp; 886 } 903 } 904 return hp; 905 } 906 887 907 888 908 public String[] getDocumentIDList(String core_element){ 889 909 890 910 Element rootElement = getRootNode(core_element); 891 911 NodeList listOfDocument = rootElement.getElementsByTagName(documentTag); … … 935 955 } 936 956 } 937 }938 return hp;939 }940 957 } 958 return hp; 959 } 960 941 961 public HashMap getIdentifierLinkNoIdentifier(){ 942 962 943 963 Element rootElement = getRootNode(rootDocument); 944 964 HashMap hp = new HashMap(); 945 965 NodeList listOfDocument = rootElement.getElementsByTagName(documentTag); 946 966 String url ="No Source Available"; 947 948 for(int s=0; s<listOfDocument.getLength() ; s++){ 967 for(int s=0; s<listOfDocument.getLength() ; s++){ 949 968 Node docNode = listOfDocument.item(s); 950 969 String HashID = docNode.getAttributes().item(0).getNodeValue(); 951 970 InternalLink il = new InternalLink(); 952 953 954 }955 return hp;956 }971 il.increaseElement(HashID); 972 hp.put(HashID, il); 973 } 974 return hp; 975 } 957 976 }
Note:
See TracChangeset
for help on using the changeset viewer.