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 de.tuberlin.ivs.owl.service.OwlsParser;
36 import java.io.PrintStream;
37
38 /***
39 * Implements the profile matching.
40 *
41 * @author Stefan Tang (steftang@stanford.edu), Christoph Liebetruth (christophl@voelcker.com)
42 * @version 1.1
43 */
44 public class ProfileMatching {
45
46 /***
47 * The output stream that output information is written to.
48 */
49 private PrintStream outWriter;
50
51 /***
52 * Default constructor.
53 * @param out The output stream that output information is written to.
54 */
55 public ProfileMatching(PrintStream out) {
56 outWriter = out;
57 }
58
59 /***
60 * Both profile categories are equivalent.
61 */
62 public static int MATCH = 3;
63
64 /***
65 * The profile category of the advertised service is subsumed by the
66 * category of the requested service.
67 */
68 public static int SUBSUMES = 2;
69
70 /***
71 * At least one of the profiles is unclassified.
72 */
73 public static int UNCLASSIFIED = 1;
74
75 /***
76 * The two concepts that classify the profiles are in no relation with each
77 * other.
78 */
79 public static int FAIL = 0;
80
81
82 /***
83 * Performs the profile matching for two profiles based on information in
84 * the current knowledge base.
85 * @param reqServiceCat The classname of the profile of the requested service.
86 * @param advServiceCat The classname of the profile of the advertised service.
87 * @param reasoner An instance of the reasoner class that holds the current
88 * knowledge base.
89 * @return An integer value denoting the matching result.
90 */
91 public int match(String reqServiceCat, String advServiceCat, Reasoner reasoner) {
92 if (reqServiceCat==null || advServiceCat==null) {
93 return UNCLASSIFIED;
94 }
95 if (reqServiceCat.equals(OwlsParser.profileID) || advServiceCat.equals(OwlsParser.profileID)) {
96 return UNCLASSIFIED;
97 } else {
98 int match = reasoner.conceptMatch(reqServiceCat, advServiceCat);
99 if (match == Reasoner.EQUIVALENT) {
100 return MATCH;
101 }
102 if (match == Reasoner.SUBSUMES) {
103 return SUBSUMES;
104 }
105 else {
106 return FAIL;
107 }
108 }
109 }
110
111 /***
112 * Writes a message to the output stream if the stream is initialized.
113 * @param message The message to be written.
114 */
115 private void writeLog(String message) {
116 if (outWriter!=null) {
117 outWriter.println(message);
118 }
119 }
120
121 }