001 /***************************************************************************/
002 /* Copyright (C) 2010-2011, Sebastian Hellmann */
003 /* Note: If you need parts of NLP2RDF in another licence due to licence */
004 /* incompatibility, please mail hellmann@informatik.uni-leipzig.de */
005 /* */
006 /* This file is part of NLP2RDF. */
007 /* */
008 /* NLP2RDF is free software; you can redistribute it and/or modify */
009 /* it under the terms of the GNU General Public License as published by */
010 /* the Free Software Foundation; either version 3 of the License, or */
011 /* (at your option) any later version. */
012 /* */
013 /* NLP2RDF is distributed in the hope that it will be useful, */
014 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
015 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
016 /* GNU General Public License for more details. */
017 /* */
018 /* You should have received a copy of the GNU General Public License */
019 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
020 /***************************************************************************/
021
022 package org.nlp2rdf.core.util;
023
024 import com.hp.hpl.jena.ontology.Individual;
025 import com.jamonapi.Monitor;
026 import com.jamonapi.MonitorFactory;
027 import org.nlp2rdf.core.Span;
028 import org.nlp2rdf.core.URIGenerator;
029
030 import java.util.Comparator;
031
032 /**
033 */
034 public class URIComparator implements Comparator<Individual> {
035
036 final String prefix;
037 final String text;
038 final URIGenerator uriGenerator;
039
040 public URIComparator(String prefix, String text, URIGenerator uriGenerator) {
041 this.prefix = prefix;
042 this.text = text;
043 this.uriGenerator = uriGenerator;
044 }
045
046 @Override
047 public int compare(Individual o1, Individual o2) {
048 Monitor mon = MonitorFactory.getTimeMonitor("compareSpansOfURIs").start();
049 try {
050
051 if (o1.getURI().equals(o2)) {
052 return 0;
053 }
054 Span a = uriGenerator.getSpanFor(prefix, o1.getURI(), text);
055 Span b = uriGenerator.getSpanFor(prefix, o2.getURI(), text);
056 return a.compareTo(b);
057 } finally {
058 mon.stop();
059 }
060 }
061
062 @Override
063 public boolean equals(Object obj) {
064 return this == obj;
065 }
066 }