<%@ page import="java.util.*" %> <%@ page import="de.dfki.mycbr.*" %> <%@ page import="de.dfki.mycbr.retrieval.*" %> <%@ page import="de.dfki.mycbr.model.vocabulary.*" %> <%@ page import="de.dfki.mycbr.model.casebase.*" %> <%@ page import="de.dfki.mycbr.modelprovider.*" %> myCBR <% final String projectsPath = "/home/lzilles/apps/apache-tomcat-5.5.28/webapps/myCBRWebDemo/projects"; final String projectName = "used_cars_flat"; final String className = "Car"; MyCBR_Facade facade = new MyCBR_Facade(projectsPath + "/" + projectName + "_CBR_CASEBASE.XML"); CBRProject project = facade.getProject(); ModelCls modelClass = facade.getModelClsByName(className); DefaultQuery query = new DefaultQuery(modelClass); ModelSlot slot = null; RetrievalResults results = null; // caseInstances is used for submitting a query from a case. Vector caseInstances = new Vector(modelClass.getDirectCaseInstances()); // If a case has been chosen, a parameter case with a number // is specified in the request String index = request.getParameter("case"); String undefined = SpecialValueHandler.SPECIAL_VALUE_UNDEFINED.toString(); boolean isEmpty = true; if ( ( index != null ) && ( index != "" ) ) { // If a case has been chosen the current query is based on it CaseInstance caseInstance = caseInstances.get(Integer.parseInt(index)-1); query = new DefaultQuery(caseInstance); } else { // if the page has been loaded by submitting a query a value for // each slot used by this query is specified by its name as POST variable for ( Iterator it = modelClass.listSlots().iterator(); it.hasNext(); ) { slot = (ModelSlot) it.next(); // Get value of POST variable Object queryValue = request.getParameter(slot.getName().replaceAll(" ", "_")); // if the slot was not used by the query // the value should be SpecialValueHandler.SPECIAL_VALUE_UNDEFINED if ( queryValue == null || "".equals(queryValue) || undefined.equals(queryValue) ) { query.setSlotValue(slot, SpecialValueHandler.SPECIAL_VALUE_UNDEFINED); continue; } isEmpty = false; // set the value for the slot of the current query to the value used // by the submitted query, so that the last submitted query is visible Object valueType = slot.getValueType().newInstance(queryValue.toString()); query.setSlotValue(slot, valueType); } } // perform retrieval if ( !isEmpty ) { RetrievalEngine retrievalEngine = facade.getRetrievalEngine(); results = retrievalEngine.retrieve(query, project.getActiveSMFs(modelClass), true); }%>

Project: <%= project.getProjectName() %> > Base class: <%= query.getModelCls().getName() %>

<% int slotId = 0; int j = 0; if ( modelClass != null ) { for ( Iterator it = modelClass.listSlots().iterator(); it.hasNext(); ) { slot = (ModelSlot) it.next(); slotId++; Object queryValue = query.getSlotValue(slot); String queryValueString = null; if ( queryValue == null ) { queryValueString = undefined; } else { queryValueString = queryValue.toString(); } // create a new column for each fifth slot if ( j%4 == 0 ) { %> <% } %> <% if ( j%4 == 3 ) { %> <% } j++; } // end for // if last row has not been closed, since the slots are not a multiple of 4 if ( (--j)%4 != 3 ) { %> <% } } else { %> <% } %>
<%= slot.getName() %> <%ValueType valueType = slot.getValueType(); if ( valueType == ValueType.STRING || valueType == ValueType.INTEGER || valueType == ValueType.FLOAT ){ if ( ( slot.getMinimumValue() != null ) && ( slot.getMaximumValue() != null ) ) { %> " type="hidden" value="<%=slot.getMinimumValue() %>" /> " type="hidden" value="<%=slot.getMaximumValue()%>" /> <% } %> " id="<%=slot.getName().replaceAll(" ", "_")%>" type="text" value="<%= query.getSlotValue(slot) %>" /> <% } else if ( slot.getValueType() == ValueType.SYMBOL ) { %> <% } else { %> N.A. <% } %>
    
From Case:    
   
<%-- end table queryParams --%> <% if ( results != null ) { // get the rankings which should be displayed Vector ranking = results.getRanking(); Vector slots = new Vector(modelClass.listSlots()); // By default, the rankings to be displayed // are the first five rankings int begin = 0; int end = Math.min(ranking.size(), 5); // if the hidden field "begin" does exist and has a value // use this as the first ranking to be displayed. // Use the value of the hidden field "end" as the // last ranking to be displayed if((request.getParameter("begin")!=null)&&(request.getParameter("begin")!="")){ begin = Integer.parseInt(request.getParameter("begin")); end = Integer.parseInt(request.getParameter("end")); } %>

<% // if the first ranking is not shown, enable the first and second arrow if ( begin != 0 ) { %> [1 - <%= 5 %>] [<%= begin %> - <%= end-1 %>] <% } // if the last ranking is not shown, enable the third and fourth arrow if ( end < ranking.size() ) { %> [<%= begin + 2 %> - <%= end + 1 %>] [<%= ranking.size() - 4 %> - <%= ranking.size() %>] <% } %>

<% for ( int row=-1 ; row < slots.size(); row++ ) { slot = null; if ( row > -1 ) { slot = slots.get(row); }%> <% if ( row == -1 ) { %> <% } else { %> <% if ( row%2 == 0 ) { %> <% } else { %> <% } %> <% } for ( int i = begin; i < end; i++ ) { AssessedInstance assessedInstance = (AssessedInstance)ranking.get(i); Explanation explanation = assessedInstance.explanation; if ( slot != null ) { explanation = assessedInstance.explanation.getLocalExplanation(slot); } String explanationTxt = "?"; if ( explanation != null ) { explanationTxt = explanation.getComments().replaceAll("\n", "; ") + "Similarity: " + Helper.getSimilarityStr(explanation.getSimilarity()); } if ( slot == null ) { %> <% } else if ( row != -1 ) { if ( row%2 == 0 ) { %> <% } %> <% } %> <% } %>
<%= (slot==null? " ": slot.getName()) %> <%= (slot==null? "Query": query.getSlotValue(slot)) %> <%= (slot==null? " ": slot.getName()) %> <%= (slot==null? "Query": query.getSlotValue(slot)) %> <%= (slot==null? " ": slot.getName()) %> <%= (slot==null? "Query": query.getSlotValue(slot)) %> <%= "Rank: " + (i+1) + "
Name: " + assessedInstance.inst.getName() + "
Similarity: " + Helper.getSimilarityStr(assessedInstance.similarity) %>
<%= assessedInstance.inst.getSlotValue(slot)%> <% } else { %> <%= assessedInstance.inst.getSlotValue(slot)%> <% } %>

<%-- Hidden fields to save the rankings which should be displayed --%> <%-- Number of rankings available --%>

<% } %>