1 /***
2 *
3 * The owl-s matcher software is subject to the GNU Lesser General
4 * Public License Version 2.1 (the "License"). You may not copy or use this
5 * file, in either source code or executable form, except in compliance
6 * with the License. You may obtain a copy of the License at
7 * http://www.fsf.org/licenses/lgpl.txt or http://www.opensource.org/.
8 *
9 * Software distributed under the License is distributed on an "AS IS"
10 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied without
11 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 * PURPOSE. See the License for the specific language governing rights and
13 * limitations under the License.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this distribution; if not, write to the
17 *
18 * Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307 USA
21 *
22 * Copyright (C) 2003-2004
23 * TU Berlin, FG IVS
24 * Stefan Tang,
25 * Christoph Liebetruth,
26 * Michael C. Jaeger,
27 *
28 * More information available at http://ivs.tu-berlin.de/
29 *
30 * $Id$
31 *
32 */
33 package de.tuberlin.ivs.owl.matching;
34
35 import java.util.Vector;
36 import de.tuberlin.ivs.owl.service.Input;
37 import java.io.PrintStream;
38
39 /***
40 * Implements the output parameter matching.
41 *
42 * @author Stefan Tang (steftang@stanford.edu), Christoph Liebetruth (christophl@voelcker.com)
43 * @version 1.1
44 */
45 public class InputParameterMatching {
46
47 /***
48 * The output stream that output information is written to.
49 */
50 private PrintStream outWriter;
51
52 /***
53 * Every input of the advertised service could be matched exactly with one
54 * input parameter of the requested service. For every input pair the
55 * property-match degree and type-match degree is Equivalent.
56 */
57 public static int MATCH = 5;
58
59 /***
60 * Every input of the advertised service could be matched with one input of
61 * the requested service. For every input pair the property-match degree is
62 * Equivalent but at least for one input pair the type-match degree is Subsumes.
63 */
64 public static int TYPE_SUBSUME = 4;
65
66 /***
67 * Every input of the advertised service could be matched with one input of
68 * the requested service. For every input pair the property-match degree is
69 * Equivalent but at least for one input pair the type-match degree is Invert
70 * Subsumes.
71 */
72 public static int TYPE_INVERT = 3;
73
74 /***
75 * Every input of the advertised service could be matched with one input of
76 * the requested service. For every input pair the property-match degree is
77 * either Equivalent or Subproperty, but we have at least one input pair
78 * matched with degree Subproperty, and the type-match degree is Subsumes,
79 * Invert Subsumes or Equivalent.
80 */
81 public static int SUBPROPERTY = 2;
82
83 /***
84 * Every input of the advertised service has been matched with an input of
85 * the requested service. However, for at least one input pair the
86 * property-match degree is unclassified.
87 */
88 public static int UNCLASSIFIED = 1;
89
90 /***
91 * There is at least one input of the advertised service for which there
92 * exists no matching input of the requested service.
93 */
94 public static int FAIL = 0;
95
96 /***
97 * Default constructor.
98 * @param out The output stream that output information is written to.
99 */
100 public InputParameterMatching(PrintStream out) {
101 outWriter = out;
102 }
103
104 /***
105 * Matches all inputs of the advertised service against all inputs of
106 * the requested Service.
107 * @param reqInputsList A vector containing all inputs of the requested service.
108 * @param advInputsList A vector containing all inputs of the advertised service.
109 * @param reasoner An instance of the reasoner class that holds the current
110 * knowledge base.
111 * @return An integer value denoting the matching result.
112 */
113 public int match(Vector reqInputsList, Vector advInputsList, Reasoner reasoner) {
114 if (Options.extendedResult==null) {
115 Options.extendedResult = new ExtendedMatchingResult();
116 }
117 if (advInputsList==null) {
118 Options.extendedResult.setInputMatching(MATCH);
119 return MATCH;
120 }
121 int minOverallRank = 9;
122 for (int i=0; i<advInputsList.size(); i++) {
123 Input advInput = (Input)advInputsList.elementAt(i);
124 Input bestMatch = null;
125 int maxRank = 0;
126 if (reqInputsList!=null) {
127 for (int j = 0; j < reqInputsList.size(); j++) {
128 Input tempReqInput = (Input) reqInputsList.elementAt(j);
129 int rank = reasoner.rankForParameters(tempReqInput, advInput);
130 if (rank > maxRank) {
131 maxRank = rank;
132 bestMatch = tempReqInput;
133 }
134 }
135 }
136 if (bestMatch==null) {
137 Options.extendedResult.addUnmatchedAdvInput(advInput);
138 Options.extendedResult.setInputMatching(FAIL);
139 return FAIL;
140 }
141 if (maxRank<minOverallRank) {
142 minOverallRank = maxRank;
143 }
144 Options.extendedResult.addMatchedAdvInput(advInput,bestMatch);
145 }
146 if (minOverallRank==1 || minOverallRank==2 || minOverallRank==3) {
147 Options.extendedResult.setInputMatching(UNCLASSIFIED);
148 return UNCLASSIFIED;
149 } else if (minOverallRank==4 || minOverallRank==5 || minOverallRank==6) {
150 Options.extendedResult.setInputMatching(SUBPROPERTY);
151 return SUBPROPERTY;
152 } else if (minOverallRank==7) {
153 Options.extendedResult.setInputMatching(TYPE_INVERT);
154 return TYPE_INVERT;
155 } else if (minOverallRank==8) {
156 Options.extendedResult.setInputMatching(TYPE_SUBSUME);
157 return TYPE_SUBSUME;
158 } else {
159 Options.extendedResult.setInputMatching(MATCH);
160 return MATCH;
161 }
162 }
163
164 /***
165 * Writes a message to the output stream if the stream is initialized.
166 * @param message The message to be written.
167 */
168 private void writeLog(String message) {
169 if (outWriter!=null) {
170 outWriter.println(message);
171 }
172 }
173
174 }