[8780cbec] | 1 | package edu.stanford.peer.rbtm; |
---|
| 2 | |
---|
| 3 | import java.io.*; |
---|
| 4 | import java.util.*; |
---|
| 5 | import edu.stanford.peer.rbtm.engine.*; |
---|
| 6 | import edu.stanford.peer.rbtm.credential.*; |
---|
| 7 | import edu.stanford.peer.rbtm.util.*; |
---|
| 8 | |
---|
| 9 | public class Test |
---|
| 10 | { |
---|
| 11 | public static void main(String args[]) throws Exception { |
---|
| 12 | //test1(); |
---|
| 13 | test3(); |
---|
| 14 | //test3(Integer.parseInt(args[0]), Integer.parseInt(args[1])); |
---|
| 15 | } |
---|
| 16 | |
---|
| 17 | static void test1() throws Exception { |
---|
| 18 | CredentialManager cs = new CredentialManager(); |
---|
| 19 | cs.addCredential(new StaticCredential("university", "professors", "university.depts.professors")); |
---|
| 20 | cs.addCredential(new StaticCredential("dept_cs", "professors", "mitchell")); |
---|
| 21 | cs.addCredential(new StaticCredential("university", "depts", "dept_cs")); |
---|
| 22 | System.out.println(cs.toString()); |
---|
| 23 | System.out.println(); |
---|
| 24 | cs.removeCredential(new StaticCredential("university", "depts", "dept_cs")); |
---|
| 25 | System.out.println(cs.toString()); |
---|
| 26 | System.out.println(); |
---|
| 27 | |
---|
| 28 | Role r = new Role("university", "professors"); |
---|
| 29 | System.out.println(cs.backwardSearch(r)); |
---|
| 30 | System.out.println(cs.forwardSearch(new SimpleEntity("mitchell"))); |
---|
| 31 | |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | static void test2() throws Exception { |
---|
| 35 | CredentialManager cs = new CredentialManager(); |
---|
| 36 | SimpleEntity tony = new SimpleEntity("Tony"), |
---|
| 37 | carmela = new SimpleEntity("Carmela"), |
---|
| 38 | melfi = new SimpleEntity("Jennifer Melfi"), |
---|
| 39 | livia = new SimpleEntity("Livia"), |
---|
| 40 | junior = new SimpleEntity("Junior"), |
---|
| 41 | chris = new SimpleEntity("Chris Moltisanti"), |
---|
| 42 | meadow = new SimpleEntity("Meadow"), |
---|
| 43 | anthony = new SimpleEntity("Anthony Jr."), |
---|
| 44 | paulie = new SimpleEntity("Paulie Walnuts"), |
---|
| 45 | jackie = new SimpleEntity("Jackie Aprile"); |
---|
| 46 | |
---|
| 47 | Role tonyWifeRole = new Role(tony, "Wife"), |
---|
| 48 | tonyFamilyRole = new Role(tony, "Family Members"), |
---|
| 49 | tonyChildrenRole = new Role(tony, "Children"), |
---|
| 50 | tonyCrewRole = new Role(tony, "Crew"), |
---|
| 51 | tonyMotherRole = new Role(tony, "Mother"), |
---|
| 52 | tonyBossRole = new Role(tony, "Boss"), |
---|
| 53 | tonyUncleRole = new Role(tony, "Uncle"), |
---|
| 54 | melfiPatientRole = new Role(melfi, "Patients"), |
---|
| 55 | melfiPreferredPatientRole = new Role(melfi, "Preferred Patients"), |
---|
| 56 | chrisBossRole = new Role(chris, "Boss"), |
---|
| 57 | chrisActingBossRole = new Role(chris, "ActingBoss"), |
---|
| 58 | chrisGangRole = new Role(chris, "Gang"); |
---|
| 59 | |
---|
| 60 | ArrayList tonyCreds = new ArrayList(20); |
---|
| 61 | |
---|
| 62 | tonyCreds.add(new StaticCredential(tonyWifeRole, carmela)); |
---|
| 63 | tonyCreds.add(new StaticCredential(tonyFamilyRole, tonyWifeRole)); |
---|
| 64 | tonyCreds.add(new StaticCredential(tonyFamilyRole, tonyChildrenRole)); |
---|
| 65 | tonyCreds.add(new StaticCredential(tonyChildrenRole, meadow)); |
---|
| 66 | tonyCreds.add(new StaticCredential(tonyChildrenRole, anthony)); |
---|
| 67 | tonyCreds.add(new StaticCredential(tonyCrewRole, chris)); |
---|
| 68 | tonyCreds.add(new StaticCredential(tonyCrewRole, paulie)); |
---|
| 69 | tonyCreds.add(new StaticCredential(tonyMotherRole, livia)); |
---|
| 70 | tonyCreds.add(new StaticCredential(tonyBossRole, jackie)); |
---|
| 71 | tonyCreds.add(new StaticCredential(tonyUncleRole, junior)); |
---|
| 72 | // Setting up credentials for toni |
---|
| 73 | cs.addCredentials(tonyCreds); |
---|
| 74 | |
---|
| 75 | ArrayList melfiCreds = new ArrayList(5); |
---|
| 76 | melfiCreds.add(new StaticCredential(melfiPatientRole, melfiPreferredPatientRole)); |
---|
| 77 | melfiCreds.add(new StaticCredential(melfiPreferredPatientRole, tony)); |
---|
| 78 | cs.addCredentials(melfiCreds); |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | ArrayList chrisCreds = new ArrayList(5); |
---|
| 82 | cs.addCredential(new StaticCredential(chrisBossRole, tony)); |
---|
| 83 | cs.addCredential(new StaticCredential(chrisActingBossRole, tonyBossRole)); |
---|
| 84 | cs.addCredential(new StaticCredential(chrisGangRole, new LinkedRole(chrisBossRole, "Crew"))); |
---|
| 85 | |
---|
| 86 | System.out.println(cs.toString()); |
---|
| 87 | System.out.println(); |
---|
| 88 | System.out.println(cs.forwardSearch(carmela)); |
---|
| 89 | System.out.println(); |
---|
| 90 | |
---|
| 91 | cs.removeCredential(new StaticCredential(chrisBossRole, tony)); |
---|
| 92 | cs.removeCredential(new StaticCredential(chrisActingBossRole, tonyBossRole)); |
---|
| 93 | |
---|
| 94 | cs.addCredential(new StaticCredential(chrisGangRole, new Role("Tony", "Wife"))); |
---|
| 95 | cs.addCredential(new StaticCredential(new Role("Meadow", "Mother"), new Role("Tony", "Wife"))); |
---|
| 96 | |
---|
| 97 | System.out.println(cs.toString()); |
---|
| 98 | System.out.println(); |
---|
| 99 | System.out.println(cs.forwardSearch(carmela)); |
---|
| 100 | System.out.println(); |
---|
| 101 | |
---|
| 102 | //System.out.println(cs.forwardSearch(jackie)); |
---|
| 103 | //System.out.println(); |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | static void test3() throws Exception |
---|
| 108 | { |
---|
| 109 | CredentialManager store = new CredentialManager(); |
---|
| 110 | |
---|
| 111 | store.addCredential(new StaticCredential("sbose", "picturesRead", "sbose.family")); |
---|
| 112 | store.addCredential(new StaticCredential("sbose", "picturesWrite", "sbose.family")); |
---|
| 113 | store.addCredential(new StaticCredential("sbose", "picturesRead", "sbose.family.friends")); |
---|
| 114 | store.addCredential(new StaticCredential("sbose", "picturesRead", "patrick")); |
---|
| 115 | store.addCredential(new StaticCredential("sbose", "picturesWrite", "andrew")); |
---|
| 116 | store.addCredential(new StaticCredential("sbose", "picturesWrite", "patrick")); |
---|
| 117 | |
---|
| 118 | System.out.println(store.toString() + "\n\n"); |
---|
| 119 | |
---|
| 120 | ResultEvidenceMap result = store.forwardSearch(new SimpleEntity("andrew")); |
---|
| 121 | Set resultSet = result.resultSet(); |
---|
| 122 | System.out.println("forward andrew is: " + resultSet); |
---|
| 123 | Iterator it = resultSet.iterator(); |
---|
| 124 | while (it.hasNext()) { |
---|
| 125 | System.out.println(it.next().toString()); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | //add a credential |
---|
| 129 | store.addCredential(new StaticCredential("sbose", "picturesRead", "andrew")); |
---|
| 130 | |
---|
| 131 | System.out.println("\n\n added credential sbose.picturesRead <- andrew"); |
---|
| 132 | |
---|
| 133 | System.out.println("\n" + store.toString() + "\n\n" + "forward search on entity andrew:"); |
---|
| 134 | |
---|
| 135 | result = store.forwardSearch(new SimpleEntity("andrew")); |
---|
| 136 | resultSet = result.resultSet(); |
---|
| 137 | System.out.println("forward andrew is: " + resultSet); |
---|
| 138 | it = resultSet.iterator(); |
---|
| 139 | while (it.hasNext()) { |
---|
| 140 | System.out.println(it.next().toString()); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | |
---|
| 144 | //remove a credential |
---|
| 145 | // |
---|
| 146 | // |
---|
| 147 | |
---|
| 148 | store.removeCredential(new StaticCredential("sbose", "picturesWrite", "patrick")); |
---|
| 149 | |
---|
| 150 | System.out.println("\n\n removed credential sbose.picturesWrite <- patrick"); |
---|
| 151 | |
---|
| 152 | System.out.println("\n" + store.toString() + "\n\n" + "forward search on patrick:"); |
---|
| 153 | |
---|
| 154 | result = store.forwardSearch(new SimpleEntity("patrick")); |
---|
| 155 | resultSet = result.resultSet(); |
---|
| 156 | it = resultSet.iterator(); |
---|
| 157 | while (it.hasNext()) { |
---|
| 158 | System.out.println(it.next().toString()); |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | static void test4(int l, int n) throws Exception { |
---|
| 165 | CredentialManager cs = new CredentialManager(); |
---|
| 166 | for (int j=0; j<n; j++) { |
---|
| 167 | cs.addCredential(new StaticCredential("K", "C", "K.C"+l+".B"+j)); |
---|
| 168 | } |
---|
| 169 | cs.addCredential(new StaticCredential("K", "C1", "K0.A")); |
---|
| 170 | for (int i=1; i<l; i++) { |
---|
| 171 | int j = i+1; |
---|
| 172 | cs.addCredential(new StaticCredential("K", "C"+j, "K.C"+i+".A")); |
---|
| 173 | } |
---|
| 174 | for (int i=0; i<n; i++) { |
---|
| 175 | cs.addCredential(new StaticCredential("K0", "A", "K"+i)); |
---|
| 176 | } |
---|
| 177 | for (int i=0; i<n; i++) { |
---|
| 178 | int j = (i+1) % n; |
---|
| 179 | cs.addCredential(new StaticCredential("K"+i, "A", "K"+j+".A")); |
---|
| 180 | } |
---|
| 181 | System.out.println(cs.toString()); |
---|
| 182 | cs.forwardSearch(new SimpleEntity("K0")); |
---|
| 183 | |
---|
| 184 | cs.backwardSearch(new Role("K", "C")); |
---|
| 185 | |
---|
| 186 | //engine.bidirectionSearch(new Role("K0", "B0"), new Role("K", "C")); |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | } |
---|