Project

General

Profile

« Previous | Next » 

Revision 8768

process all the returned annotation suggestions until we find one that is appropriately located in the subclass hierarchy for the given superclass.

View differences:

src/edu/ucsb/nceas/metacat/annotation/BioPortalService.java
9 9
import org.w3c.dom.Document;
10 10
import org.w3c.dom.NodeList;
11 11

  
12
import com.hp.hpl.jena.ontology.ConversionException;
12 13
import com.hp.hpl.jena.ontology.OntClass;
13 14
import com.hp.hpl.jena.rdf.model.Resource;
14 15

  
......
31 32
	 */
32 33
	public static Resource lookupAnnotationClass(OntClass superClass, String text, String ontologies) {
33 34
		
35
		// no point calling the service
36
		if (text == null || text.length() == 0) {
37
			return null;
38
		}
39
		
34 40
		try {
35 41
			
36 42
			String urlParameters = "apikey=" + API_KEY;
......
46 52
			Document doc = XMLUtilities.getXMLReaderAsDOMDocument(new InputStreamReader(is, "UTF-8"));
47 53
			NodeList classNodeList = XMLUtilities.getNodeListWithXPath(doc, "//annotation/annotatedClass/id");
48 54
			if (classNodeList != null && classNodeList.getLength() > 0) {
49
				String classURI = classNodeList.item(0).getFirstChild().getNodeValue();
50
				logMetacat.info("annotator suggested: " + classURI);
51
				Resource subclass = superClass.getModel().getResource(classURI);
52
				// check that it is a subclass of superClass
53
				if (superClass.hasSubClass(subclass)) {
54
					return subclass;
55
				for (int i = 0; i < classNodeList.getLength(); i++) {
56
					String classURI = classNodeList.item(i).getFirstChild().getNodeValue();
57
					logMetacat.info("annotator suggested: " + classURI);
58
					Resource subclass = superClass.getModel().getResource(classURI);
59
					// check that it is a subclass of superClass
60
					boolean isSubclass = false;
61
					try {
62
						isSubclass = superClass.hasSubClass(subclass);
63
					} catch (ConversionException ce) {
64
						logMetacat.warn("Skipping unknown subclass: " + classURI, ce);
65
						// try the next one
66
						continue;
67
					}
68
					if (isSubclass) {
69
						return subclass;
70
					}
55 71
				}
72
				
56 73
			}
57 74
		} catch (Exception e) {
58 75
			logMetacat.error("Could not lookup BioPortal annotation for text=" + text, e);

Also available in: Unified diff