<%@ page import="java.util.*" %> <%@ page import="org.w3.www._2001.sw.Europe.skos.ServiceAPI.*, org.w3.www._2001.sw.Europe.skos.namespace.*" %> <%@ page import="org.apache.axis.AxisFault" %> <%@ page import="java.text.SimpleDateFormat" %> <% //********************************************************************// // This is a simple jsp application that demonstrates the use of // nbii thesaurus web service // This jsp uses java wrapper objects that are created by WSDL2Java utility. // The command for running this utiltiy is // java org.apache.axis.wsdl.WSDL2Java http://nbii-thesaurus.ornl.gov/ws/services/SKOSThesaurusService?wsdl // WSDL2Java is a utility under the Apache Axis project which will build the stubs necessary to make web service calls. // Alternately the client stub files could be downloaded from the main page. // Please find the link to the axis project under developer resources in the home page. // Make sure that you have axis.jar file in your classpath while executing this command, // as that is where org.apache.axis.wsdl.WSDL2Java resides. // You will find a number of .java files generated in a subdirectory under org.w3.www._2001.sw.Europe.skos.namespace and org.w3.www._2001.sw.Europe.skos.ServiceAPI // These are the stub files or wrapper classes. // The wrapper classes allow you to code in java data types and convert them transparently to XML. // Some useful links // --http://ws.apache.org/axis/java/reference.html WSDL2Java reference // --http://ws.apache.org/axis/ Axis // updates: // 1) 01/19/05: updated to handle exceptions/faults that are generated by invalid strings // and also to ensure minimum length //********************************************************************// %> SKOS Thesaurus Client
                 
                                                                                                                                                                      Main>>

              NBII Thesaurus Web Service Prototype - Using SKOS



<% String usrTerm = ""; if(request.getParameter("usrTerm")!=null) { usrTerm = request.getParameter("usrTerm"); } %>
Enter a Term:        
Choose a Term Group:        














<% if(request.getParameter("usrTerm")!=null && !request.getParameter("usrTerm").equals("")) { String BT = "BT"; String NT = "NT"; String RT = "RT"; String SC = "SC"; String SN = "SN"; String UF = "UF"; String USE = "USE"; //the following declarations are to get the associated terms off the conceptResult object. They are stored in the following order. So use the following variables or their values to retrieve the right associated group of terms int BROADER = 0; int NARROWER = 1; int RELATED = 2; int SUBJECT = 3; int USEFOR = 4; boolean displayAll = false; usrTerm = request.getParameter("usrTerm"); String [] termGroup = request.getParameterValues("termGroup"); ArrayList termGroupList = new ArrayList(); for (int i=0;i
<% try { SKOSThesaurusService skosService = new SKOSThesaurusServiceLocator(); SKOSThesaurus thesaurus = skosService.getSKOSThesaurusService(); URI thesuri = new URI(); thesuri.setUri("http://nbii-thesaurus.ornl.gov/ws/services/SKOSThesaurusService"); //STEP1: first get the entire terms from the db based on the user input ConceptResult[] matchingTerms = thesaurus.getConceptResultsByKeyword(usrTerm, thesuri); if(matchingTerms.length >0) { if(usrTerm.indexOf("http://thesaurus.nbii.gov/Concept/") != -1) { usrTerm = matchingTerms[0].getConcept().getPreferredLabel(); } %> <% //STEP2: for each retrieved terms get the synonyms for each attribute (i.e. for BT,NT.SC etc..) for(int tm=0; tm < matchingTerms.length;tm++) { ConceptResult currConResult = matchingTerms[tm]; Concept currMatchConcept = currConResult.getConcept(); String prefLabel = ""; ConceptRelatives[] conceptRelatives = null; if(currMatchConcept != null) { prefLabel = currMatchConcept.getPreferredLabel(); conceptRelatives = currConResult.getConceptRelatives(); } out.println(""); //display synonyms for a particular Term Category if(conceptRelatives != null) { if(displayAll||termGroupList.contains(BT)) { //broader terms ConceptRelatives btConRel = conceptRelatives[BROADER]; out.println(""); out.println(""); out.println(""); } else { out.println("No broader terms"); } } if(displayAll||termGroupList.contains(NT)) { //narrower terms ConceptRelatives ntConRel = conceptRelatives[NARROWER]; out.println(""); out.println(""); out.println(""); } else { out.println("No narrower terms"); } } if(displayAll||termGroupList.contains(RT)) { //related terms ConceptRelatives rtConRel = conceptRelatives[RELATED]; out.println(""); out.println(""); out.println(""); } else { out.println("No related terms"); } } if(displayAll||termGroupList.contains(SC)) { //subject category ConceptRelatives subjConRel = conceptRelatives[SUBJECT]; out.println(""); out.println(""); out.println(""); } else { out.println("No subject categories"); } } if(displayAll||termGroupList.contains(SN)) { out.println(""); out.println(""); //String[] ntTermsList = (String[])port.getNTTerms(usrTerm); out.println(""); } if(displayAll||termGroupList.contains(UF)) { //use for terms ConceptRelatives ufConRel = conceptRelatives[USEFOR]; out.println(""); out.println(""); out.println(""); } else { out.println("No use for terms"); } } if(displayAll||termGroupList.contains(USE)) { String[] uTermsList = currMatchConcept.getNonPreferredLabels(); out.println(""); out.println(""); //String[] ntTermsList = (String[])port.getNTTerms(usrTerm); out.println(""); } } } } else { %>
Results for term(s) containing <%= usrTerm%>
Term GroupTerms
"+prefLabel+"
Broader Terms:"); if(btConRel != null) { Concept[] btConcepts = btConRel.getConcepts(); for(int i = 0; i < btConcepts.length; i++) { Concept currConcept = btConcepts[i]; out.println(""+currConcept.getPreferredLabel()+""); if(i < (btConcepts.length - 1)) { out.print(", "); } } out.println("
Narrower Terms:"); if(ntConRel != null) { Concept[] ntConcepts = ntConRel.getConcepts(); for(int i = 0; i < ntConcepts.length; i++) { Concept currConcept = ntConcepts[i]; out.println(""+currConcept.getPreferredLabel()+""); if(i < (ntConcepts.length - 1)) { out.print(", "); } } out.println("
Related Terms:"); if(rtConRel != null) { Concept[] rtConcepts = rtConRel.getConcepts(); for(int i = 0; i < rtConcepts.length; i++) { Concept currConcept = rtConcepts[i]; out.println(""+currConcept.getPreferredLabel()+""); if(i < (rtConcepts.length - 1)) { out.print(", "); } } out.println("
Subject Category:"); if(subjConRel != null) { Concept[] subjConcepts = subjConRel.getConcepts(); for(int i = 0; i < subjConcepts.length; i++) { Concept currConcept = subjConcepts[i]; //out.println(""+currConcept.getPreferredLabel()+""); out.println(currConcept.getPreferredLabel()); if(i < (subjConcepts.length - 1)) { out.print(", "); } } out.println("
Scope Note:"); if(currMatchConcept.getScopeNote() != null && !currMatchConcept.getScopeNote().equals("")) { out.println(currMatchConcept.getScopeNote()); } else { out.println("No scope note"); } out.println("
Use For:"); if(ufConRel != null) { Concept[] ufConcepts = ufConRel.getConcepts(); for(int i = 0; i < ufConcepts.length; i++) { Concept currConcept = ufConcepts[i]; out.println(""+currConcept.getPreferredLabel()+""); if(i < (ufConcepts.length - 1)) { out.print(", "); } } out.println("
Use:"); if(uTermsList != null && uTermsList.length > 0) { for(int i = 0; i < uTermsList.length; i++) { out.println(""+uTermsList[i]+""); if(i != uTermsList.length-1) { out.print(","); } } } else { out.println("No use terms"); } out.println("
No results found for search word <%= usrTerm%>
<% } } catch(AxisFault re) { out.println("ERROR: "+re.getFaultCode()+":"+re.getFaultString()); } catch (Exception e) { out.println("Exception caught: "+e.getMessage()); e.printStackTrace(); } } %>