Search in sources :

Example 1 with ExpressionBuilder

use of org.olat.ims.qti.process.elements.ExpressionBuilder in project OpenOLAT by OpenOLAT.

the class AssessmentContext method initSections.

private void initSections(Element assessment, Switches sw) {
    sectionContexts = new ArrayList<SectionContext>(2);
    List<Element> el_sections = new ArrayList<>();
    // <!ELEMENT sectionref (#PCDATA)>
    // <!ATTLIST sectionref %I_LinkRefId; >
    List sections = assessment.selectNodes("section|sectionref");
    for (Iterator iter = sections.iterator(); iter.hasNext(); ) {
        Element el_section = (Element) iter.next();
        // resolve sectionref into the correct sections
        if (el_section.getName().equals("sectionref")) {
            String linkRefId = el_section.attributeValue("linkrefid");
            el_section = (Element) el_section.selectSingleNode("//section[@ident='" + linkRefId + "']");
            if (el_section == null) {
                throw new RuntimeException("sectionref with ref '" + linkRefId + "' could not be resolved");
            }
        }
        el_sections.add(el_section);
    }
    Element el_selordering = (Element) assessment.selectSingleNode("selection_ordering");
    if (el_selordering != null) {
        // do some selection and ordering
        // <!ELEMENT selection_ordering (qticomment? , sequence_parameter* ,
        // selection* , order?)>
        // <!ATTLIST selection_ordering sequence_type CDATA #IMPLIED >
        // <!ELEMENT selection (sourcebank_ref? , selection_number? ,
        // selection_metadata? ,
        // (and_selection | or_selection | not_selection | selection_extension)?)>
        // <!ELEMENT sourcebank_ref (#PCDATA)>
        // not <!ELEMENT order (order_extension?)>
        // <!ATTLIST order order_type CDATA #REQUIRED >
        // <!ELEMENT selection_number (#PCDATA)>
        // not <!ELEMENT sequence_parameter (#PCDATA)>
        // not <!ATTLIST sequence_parameter %I_Pname; >
        List el_selections = el_selordering.selectNodes("selection");
        // add to the run-time-section
        for (Iterator it_selection = el_selections.iterator(); it_selection.hasNext(); ) {
            List selectedSections;
            Element el_selection = (Element) it_selection.next();
            Element el_sourcebankref = (Element) el_selection.selectSingleNode("sourcebank_ref");
            if (el_sourcebankref == null) {
                // no reference to sourcebank, -> take internal one, but dtd disallows
                // it!?? TODO
                /*
					 * 2:27 PM] <felix.jost> aus ims qti sao: [2:27 PM] <felix.jost> 3.2.1
					 * <sourcebank_ref> Description: Identifies the objectbank to which
					 * the selection and ordering rules are to be applied. This objectbank
					 * may or may not be contained in the same <questestinterop> package.
					 * [2:27 PM] <felix.jost> aber dtd: [2:28 PM] <felix.jost> <!ELEMENT
					 * questestinterop (qticomment? , (objectbank | assessment | (section |
					 * item)+))>
					 */
                selectedSections = new ArrayList();
            } else {
                String sourceBankRef = el_sourcebankref.getText();
                Element objectBank = assessInstance.getResolver().getObjectBank(sourceBankRef);
                // traverse 1.: process "and" or "or" or "not" selection to get the
                // items, if existing, otherwise take all items
                // 2.: do the selection_number
                Element andornot_selection = (Element) el_selection.selectSingleNode("and_selection|or_selection|not_selection|selection_metadata");
                StringBuilder select_expr = new StringBuilder("//section");
                if (andornot_selection != null) {
                    // some criteria, extend above xpath to select only the appropriate
                    // elements
                    select_expr.append("[");
                    String elName = andornot_selection.getName();
                    ExpressionBuilder eb = QTIHelper.getExpressionBuilder(elName);
                    eb.buildXPathExpression(andornot_selection, select_expr, false, true);
                    select_expr.append("]");
                }
                selectedSections = objectBank.selectNodes(select_expr.toString());
                el_sections.addAll(selectedSections);
            }
            Element el_selection_number = (Element) el_selection.selectSingleNode("selection_number");
            // --- 3. if selection_number exists, pick out some items
            if (el_selection_number != null) {
                String sNum = el_selection_number.getText();
                int num = new Integer(sNum).intValue();
                // now choose some x out of the items if selection_number exists
                List<Element> newList = new ArrayList<Element>();
                Random r = new Random();
                int size = el_sections.size();
                // only four
                if (num > size)
                    num = size;
                for (int i = 0; i < num; i++) {
                    int n = r.nextInt(size--);
                    Element o = el_sections.remove(n);
                    newList.add(o);
                }
                el_sections = newList;
                /*
					 * pick out items -> remove unused items from section
					 */
                sections.removeAll(el_sections);
                for (Iterator iter = sections.iterator(); iter.hasNext(); ) {
                    el_sections.remove(iter.next());
                }
            }
        // append found items to existing ones
        }
    }
    // <order order_type="Random"/>
    if (el_selordering != null) {
        Element el_order = (Element) el_selordering.selectSingleNode("order");
        if (el_order != null) {
            String order_type = el_order.attributeValue("order_type");
            if (order_type.equals("Random")) {
                Collections.shuffle(el_sections);
            }
        }
    }
    for (Iterator<Element> iter = el_sections.iterator(); iter.hasNext(); ) {
        Element section = iter.next();
        SectionContext sc = new SectionContext();
        sc.setUp(assessInstance, section, sw);
        sectionContexts.add(sc);
    }
}
Also used : Element(org.dom4j.Element) ArrayList(java.util.ArrayList) ExpressionBuilder(org.olat.ims.qti.process.elements.ExpressionBuilder) Random(java.util.Random) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with ExpressionBuilder

use of org.olat.ims.qti.process.elements.ExpressionBuilder in project OpenOLAT by OpenOLAT.

the class QTI_and_selection method buildXPathExpression.

/**
 * <!ELEMENT and_selection (selection_metadata | and_selection | or_selection | not_selection)+>
 * @see org.olat.qti.process.elements.ExpressionBuilder#buildXPathExpression(org.dom4j.Element, java.lang.StringBuilder)
 */
public void buildXPathExpression(Element selectionElement, StringBuilder expr, boolean not_switch, boolean use_switch) {
    if (use_switch && not_switch) {
        // treat this "and" node as an "or" node (we need to propagate not's down the tree, since xpath only knows !=,< etc. , but not a not
        ExpressionBuilder eb = QTIHelper.getExpressionBuilder("or_selection");
        eb.buildXPathExpression(selectionElement, expr, not_switch, false);
    } else {
        List elems = selectionElement.elements();
        // dtd: > 0
        int size = elems.size();
        for (int i = 0; i < size; i++) {
            Element child = (Element) elems.get(i);
            String name = child.getName();
            ExpressionBuilder eb = QTIHelper.getExpressionBuilder(name);
            eb.buildXPathExpression(child, expr, not_switch, true);
            if (i < size - 1)
                expr.append(" and ");
        }
    }
}
Also used : Element(org.dom4j.Element) List(java.util.List) ExpressionBuilder(org.olat.ims.qti.process.elements.ExpressionBuilder)

Example 3 with ExpressionBuilder

use of org.olat.ims.qti.process.elements.ExpressionBuilder in project OpenOLAT by OpenOLAT.

the class SectionContext method setUp.

/**
 * @param assessInstance
 * @param el_section
 * @param sw
 */
public void setUp(AssessmentInstance assessInstance, Element el_section, Switches sw) {
    this.assessInstance = assessInstance;
    this.el_section = el_section;
    this.ident = el_section.attributeValue("ident");
    init();
    Element dur = (Element) el_section.selectSingleNode("duration");
    if (dur == null) {
        // no limit
        durationLimit = -1;
    } else {
        String sdur = dur.getText();
        durationLimit = QTIHelper.parseISODuration(sdur);
        // Assesst Designer fix
        if (durationLimit == 0)
            durationLimit = -1;
    }
    // get objectives
    Element el_objectives = (Element) el_section.selectSingleNode("objectives");
    if (el_objectives != null)
        objectives = new Objectives(el_objectives);
    // ---------------------------------------------------------
    if (sw == null) {
        // no switches from the assessment context dominate
        // retrieve section switches
        Element el_control = (Element) el_section.selectSingleNode("sectioncontrol");
        if (el_control != null) {
            String feedbackswitch = el_control.attributeValue("feedbackswitch");
            String hintswitch = el_control.attributeValue("hintswitch");
            String solutionswitch = el_control.attributeValue("solutionswitch");
            feedbackswitchedon = (feedbackswitch == null) ? true : feedbackswitch.equals("Yes");
            boolean hints = (hintswitch == null) ? true : hintswitch.equals("Yes");
            boolean solutions = (solutionswitch == null) ? true : solutionswitch.equals("Yes");
            sw = new Switches(feedbackswitchedon, hints, solutions);
        }
    }
    // ----------------------- selection
    List<Element> el_items = new ArrayList<>();
    // determine which items (sections not implemented) will be chosen/selected
    // for this section
    // --- 1. take all items and resolved itemrefs which are in the section
    List items = el_section.selectNodes("item|itemref");
    for (Iterator iter = items.iterator(); iter.hasNext(); ) {
        Element el_item = (Element) iter.next();
        // % I_LinkRefId " linkrefid CDATA #REQUIRED">
        if (el_item.getName().equals("itemref")) {
            // resolve the entity first
            String linkRefId = el_item.attributeValue("linkrefid");
            el_item = (Element) el_section.selectSingleNode("//item[@ident='" + linkRefId + "']");
        // if item == null -> TODO Error
        }
        el_items.add(el_item);
    }
    // --- 2. select all items from the objectbank which fulfill the selection
    // criteria
    Element el_selordering = (Element) el_section.selectSingleNode("selection_ordering");
    if (el_selordering != null) {
        // do some selection and ordering
        // here comes the selection....
        // xpath =
        // "//item[itemmetadata/qtimetadata/qtimetadatafield[fieldlabel[text()='qmd_dificulty']
        // and fieldentry[text()='4']] or
        // itemmetadata/qtimetadata/qtimetadatafield[fieldlabel[text()='qmd_author']
        // and fieldentry[text()='felix']]]"
        // <!ELEMENT selection_ordering (qticomment? , sequence_parameter* ,
        // selection* , order?)>
        // <!ATTLIST selection_ordering sequence_type CDATA #IMPLIED >
        // <!ELEMENT selection (sourcebank_ref? , selection_number? ,
        // selection_metadata? ,
        // (and_selection | or_selection | not_selection | selection_extension)?)>
        // <!ELEMENT sourcebank_ref (#PCDATA)>
        // not <!ELEMENT order (order_extension?)>
        // <!ATTLIST order order_type CDATA #REQUIRED >
        // <!ELEMENT selection_number (#PCDATA)>
        // not <!ELEMENT sequence_parameter (#PCDATA)>
        // not <!ATTLIST sequence_parameter %I_Pname; >
        List el_selections = el_selordering.selectNodes("selection");
        // add to the run-time-section
        for (Iterator it_selection = el_selections.iterator(); it_selection.hasNext(); ) {
            List selectedItems;
            Element el_selection = (Element) it_selection.next();
            Element el_sourcebankref = (Element) el_selection.selectSingleNode("sourcebank_ref");
            if (el_sourcebankref == null) {
                // no reference to sourcebank, -> take internal one, but dtd disallows
                // it!?? TODO
                /*
					 * 2:27 PM] <felix.jost> aus ims qti sao: [2:27 PM] <felix.jost> 3.2.1
					 * <sourcebank_ref> Description: Identifies the objectbank to which
					 * the selection and ordering rules are to be applied. This objectbank
					 * may or may not be contained in the same <questestinterop> package.
					 * [2:27 PM] <felix.jost> aber dtd: [2:28 PM] <felix.jost> <!ELEMENT
					 * questestinterop (qticomment? , (objectbank | assessment | (section |
					 * item)+))>
					 */
                selectedItems = new ArrayList();
            } else {
                String sourceBankRef = el_sourcebankref.getText();
                Element objectBank = assessInstance.getResolver().getObjectBank(sourceBankRef);
                // traverse 1.: process "and" or "or" or "not" selection to get the
                // items, if existing, otherwise take all items
                // 2.: do the selection_number
                Element andornot_selection = (Element) el_selection.selectSingleNode("and_selection|or_selection|not_selection|selection_metadata");
                StringBuilder select_expr = new StringBuilder("//item");
                if (andornot_selection != null) {
                    // some criteria, extend above xpath to select only the appropriate
                    // elements
                    select_expr.append("[");
                    String elName = andornot_selection.getName();
                    ExpressionBuilder eb = QTIHelper.getExpressionBuilder(elName);
                    eb.buildXPathExpression(andornot_selection, select_expr, false, true);
                    select_expr.append("]");
                }
                selectedItems = objectBank.selectNodes(select_expr.toString());
                el_items.addAll(selectedItems);
            }
            Element el_selection_number = (Element) el_selection.selectSingleNode("selection_number");
            // --- 3. if selection_number exists, pick out some items
            if (el_selection_number != null) {
                String sNum = el_selection_number.getText();
                int num = new Integer(sNum).intValue();
                // now choose some x out of the items if selection_number exists
                List<Element> newList = new ArrayList<>();
                Random r = new Random();
                int size = el_items.size();
                // only four
                if (num > size)
                    num = size;
                for (int i = 0; i < num; i++) {
                    int n = r.nextInt(size--);
                    Element o = el_items.remove(n);
                    newList.add(o);
                }
                el_items = newList;
                /*
					 * pick out items -> remove unused items from section
					 */
                items.removeAll(el_items);
                for (Iterator iter = items.iterator(); iter.hasNext(); ) {
                    el_section.remove((Node) iter.next());
                }
            }
        // append found items to existing ones
        }
    }
    // <order order_type="Random"/>
    if (el_selordering != null) {
        Element el_order = (Element) el_selordering.selectSingleNode("order");
        if (el_order != null) {
            String order_type = el_order.attributeValue("order_type");
            if (order_type.equals("Random")) {
                Collections.shuffle(el_items);
            }
        }
    }
    // now wrap all item contexts
    itemContexts = new ArrayList<ItemContext>(10);
    for (Iterator<Element> iter = el_items.iterator(); iter.hasNext(); ) {
        Element item = iter.next();
        item.detach();
        ItemContext itc = new ItemContext();
        itc.setUp(assessInstance, item, sw);
        if (durationLimit != -1 && assessInstance.isSectionPage())
            itc.clearDurationLimit();
        itemContexts.add(itc);
    }
    // outcomesProcessing
    // <!ELEMENT section (qticomment? , duration? , qtimetadata* ,
    // objectives* , sectioncontrol* , sectionprecondition* ,
    // sectionpostcondition* ,
    // rubric* , presentation_material? ,
    // outcomes_processing* , sectionproc_extension? ,
    // sectionfeedback* , selection_ordering? ,
    // reference? , (itemref | item | sectionref | section)*)>
    // <!ELEMENT outcomes_processing (qticomment? , outcomes ,
    // objects_condition* , processing_parameter* , map_output* ,
    // outcomes_feedback_test*)>
    // <!ELEMENT outcomes (qticomment? , (decvar , interpretvar*)+)>
    // <!ELEMENT decvar (#PCDATA)>
    // <!ATTLIST decvar %I_VarName; .......cutvalue CDATA #IMPLIED >
    Element el_outpro = (Element) el_section.selectSingleNode("outcomes_processing");
    if (el_outpro != null) {
        // get the scoring model: we need it later for calculating the score
        // <!ENTITY % I_ScoreModel " scoremodel CDATA #IMPLIED">
        scoremodel = el_outpro.attributeValue("scoremodel");
        // may be null -> then assume SumOfScores
        // set the cutvalue if given (only variable score)
        cutvalue = QTIHelper.getIntAttribute(el_outpro, "outcomes/decvar[@varname='SCORE']", "cutvalue");
        List el_oft = el_outpro.selectNodes("outcomes_feedback_test");
        if (el_oft.size() != 0) {
            feedbacktesting = true;
        }
    }
}
Also used : Element(org.dom4j.Element) Objectives(org.olat.ims.qti.container.qtielements.Objectives) ArrayList(java.util.ArrayList) ExpressionBuilder(org.olat.ims.qti.process.elements.ExpressionBuilder) Random(java.util.Random) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with ExpressionBuilder

use of org.olat.ims.qti.process.elements.ExpressionBuilder in project openolat by klemens.

the class AssessmentContext method initSections.

private void initSections(Element assessment, Switches sw) {
    sectionContexts = new ArrayList<SectionContext>(2);
    List<Element> el_sections = new ArrayList<>();
    // <!ELEMENT sectionref (#PCDATA)>
    // <!ATTLIST sectionref %I_LinkRefId; >
    List sections = assessment.selectNodes("section|sectionref");
    for (Iterator iter = sections.iterator(); iter.hasNext(); ) {
        Element el_section = (Element) iter.next();
        // resolve sectionref into the correct sections
        if (el_section.getName().equals("sectionref")) {
            String linkRefId = el_section.attributeValue("linkrefid");
            el_section = (Element) el_section.selectSingleNode("//section[@ident='" + linkRefId + "']");
            if (el_section == null) {
                throw new RuntimeException("sectionref with ref '" + linkRefId + "' could not be resolved");
            }
        }
        el_sections.add(el_section);
    }
    Element el_selordering = (Element) assessment.selectSingleNode("selection_ordering");
    if (el_selordering != null) {
        // do some selection and ordering
        // <!ELEMENT selection_ordering (qticomment? , sequence_parameter* ,
        // selection* , order?)>
        // <!ATTLIST selection_ordering sequence_type CDATA #IMPLIED >
        // <!ELEMENT selection (sourcebank_ref? , selection_number? ,
        // selection_metadata? ,
        // (and_selection | or_selection | not_selection | selection_extension)?)>
        // <!ELEMENT sourcebank_ref (#PCDATA)>
        // not <!ELEMENT order (order_extension?)>
        // <!ATTLIST order order_type CDATA #REQUIRED >
        // <!ELEMENT selection_number (#PCDATA)>
        // not <!ELEMENT sequence_parameter (#PCDATA)>
        // not <!ATTLIST sequence_parameter %I_Pname; >
        List el_selections = el_selordering.selectNodes("selection");
        // add to the run-time-section
        for (Iterator it_selection = el_selections.iterator(); it_selection.hasNext(); ) {
            List selectedSections;
            Element el_selection = (Element) it_selection.next();
            Element el_sourcebankref = (Element) el_selection.selectSingleNode("sourcebank_ref");
            if (el_sourcebankref == null) {
                // no reference to sourcebank, -> take internal one, but dtd disallows
                // it!?? TODO
                /*
					 * 2:27 PM] <felix.jost> aus ims qti sao: [2:27 PM] <felix.jost> 3.2.1
					 * <sourcebank_ref> Description: Identifies the objectbank to which
					 * the selection and ordering rules are to be applied. This objectbank
					 * may or may not be contained in the same <questestinterop> package.
					 * [2:27 PM] <felix.jost> aber dtd: [2:28 PM] <felix.jost> <!ELEMENT
					 * questestinterop (qticomment? , (objectbank | assessment | (section |
					 * item)+))>
					 */
                selectedSections = new ArrayList();
            } else {
                String sourceBankRef = el_sourcebankref.getText();
                Element objectBank = assessInstance.getResolver().getObjectBank(sourceBankRef);
                // traverse 1.: process "and" or "or" or "not" selection to get the
                // items, if existing, otherwise take all items
                // 2.: do the selection_number
                Element andornot_selection = (Element) el_selection.selectSingleNode("and_selection|or_selection|not_selection|selection_metadata");
                StringBuilder select_expr = new StringBuilder("//section");
                if (andornot_selection != null) {
                    // some criteria, extend above xpath to select only the appropriate
                    // elements
                    select_expr.append("[");
                    String elName = andornot_selection.getName();
                    ExpressionBuilder eb = QTIHelper.getExpressionBuilder(elName);
                    eb.buildXPathExpression(andornot_selection, select_expr, false, true);
                    select_expr.append("]");
                }
                selectedSections = objectBank.selectNodes(select_expr.toString());
                el_sections.addAll(selectedSections);
            }
            Element el_selection_number = (Element) el_selection.selectSingleNode("selection_number");
            // --- 3. if selection_number exists, pick out some items
            if (el_selection_number != null) {
                String sNum = el_selection_number.getText();
                int num = new Integer(sNum).intValue();
                // now choose some x out of the items if selection_number exists
                List<Element> newList = new ArrayList<Element>();
                Random r = new Random();
                int size = el_sections.size();
                // only four
                if (num > size)
                    num = size;
                for (int i = 0; i < num; i++) {
                    int n = r.nextInt(size--);
                    Element o = el_sections.remove(n);
                    newList.add(o);
                }
                el_sections = newList;
                /*
					 * pick out items -> remove unused items from section
					 */
                sections.removeAll(el_sections);
                for (Iterator iter = sections.iterator(); iter.hasNext(); ) {
                    el_sections.remove(iter.next());
                }
            }
        // append found items to existing ones
        }
    }
    // <order order_type="Random"/>
    if (el_selordering != null) {
        Element el_order = (Element) el_selordering.selectSingleNode("order");
        if (el_order != null) {
            String order_type = el_order.attributeValue("order_type");
            if (order_type.equals("Random")) {
                Collections.shuffle(el_sections);
            }
        }
    }
    for (Iterator<Element> iter = el_sections.iterator(); iter.hasNext(); ) {
        Element section = iter.next();
        SectionContext sc = new SectionContext();
        sc.setUp(assessInstance, section, sw);
        sectionContexts.add(sc);
    }
}
Also used : Element(org.dom4j.Element) ArrayList(java.util.ArrayList) ExpressionBuilder(org.olat.ims.qti.process.elements.ExpressionBuilder) Random(java.util.Random) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with ExpressionBuilder

use of org.olat.ims.qti.process.elements.ExpressionBuilder in project openolat by klemens.

the class SectionContext method setUp.

/**
 * @param assessInstance
 * @param el_section
 * @param sw
 */
public void setUp(AssessmentInstance assessInstance, Element el_section, Switches sw) {
    this.assessInstance = assessInstance;
    this.el_section = el_section;
    this.ident = el_section.attributeValue("ident");
    init();
    Element dur = (Element) el_section.selectSingleNode("duration");
    if (dur == null) {
        // no limit
        durationLimit = -1;
    } else {
        String sdur = dur.getText();
        durationLimit = QTIHelper.parseISODuration(sdur);
        // Assesst Designer fix
        if (durationLimit == 0)
            durationLimit = -1;
    }
    // get objectives
    Element el_objectives = (Element) el_section.selectSingleNode("objectives");
    if (el_objectives != null)
        objectives = new Objectives(el_objectives);
    // ---------------------------------------------------------
    if (sw == null) {
        // no switches from the assessment context dominate
        // retrieve section switches
        Element el_control = (Element) el_section.selectSingleNode("sectioncontrol");
        if (el_control != null) {
            String feedbackswitch = el_control.attributeValue("feedbackswitch");
            String hintswitch = el_control.attributeValue("hintswitch");
            String solutionswitch = el_control.attributeValue("solutionswitch");
            feedbackswitchedon = (feedbackswitch == null) ? true : feedbackswitch.equals("Yes");
            boolean hints = (hintswitch == null) ? true : hintswitch.equals("Yes");
            boolean solutions = (solutionswitch == null) ? true : solutionswitch.equals("Yes");
            sw = new Switches(feedbackswitchedon, hints, solutions);
        }
    }
    // ----------------------- selection
    List<Element> el_items = new ArrayList<>();
    // determine which items (sections not implemented) will be chosen/selected
    // for this section
    // --- 1. take all items and resolved itemrefs which are in the section
    List items = el_section.selectNodes("item|itemref");
    for (Iterator iter = items.iterator(); iter.hasNext(); ) {
        Element el_item = (Element) iter.next();
        // % I_LinkRefId " linkrefid CDATA #REQUIRED">
        if (el_item.getName().equals("itemref")) {
            // resolve the entity first
            String linkRefId = el_item.attributeValue("linkrefid");
            el_item = (Element) el_section.selectSingleNode("//item[@ident='" + linkRefId + "']");
        // if item == null -> TODO Error
        }
        el_items.add(el_item);
    }
    // --- 2. select all items from the objectbank which fulfill the selection
    // criteria
    Element el_selordering = (Element) el_section.selectSingleNode("selection_ordering");
    if (el_selordering != null) {
        // do some selection and ordering
        // here comes the selection....
        // xpath =
        // "//item[itemmetadata/qtimetadata/qtimetadatafield[fieldlabel[text()='qmd_dificulty']
        // and fieldentry[text()='4']] or
        // itemmetadata/qtimetadata/qtimetadatafield[fieldlabel[text()='qmd_author']
        // and fieldentry[text()='felix']]]"
        // <!ELEMENT selection_ordering (qticomment? , sequence_parameter* ,
        // selection* , order?)>
        // <!ATTLIST selection_ordering sequence_type CDATA #IMPLIED >
        // <!ELEMENT selection (sourcebank_ref? , selection_number? ,
        // selection_metadata? ,
        // (and_selection | or_selection | not_selection | selection_extension)?)>
        // <!ELEMENT sourcebank_ref (#PCDATA)>
        // not <!ELEMENT order (order_extension?)>
        // <!ATTLIST order order_type CDATA #REQUIRED >
        // <!ELEMENT selection_number (#PCDATA)>
        // not <!ELEMENT sequence_parameter (#PCDATA)>
        // not <!ATTLIST sequence_parameter %I_Pname; >
        List el_selections = el_selordering.selectNodes("selection");
        // add to the run-time-section
        for (Iterator it_selection = el_selections.iterator(); it_selection.hasNext(); ) {
            List selectedItems;
            Element el_selection = (Element) it_selection.next();
            Element el_sourcebankref = (Element) el_selection.selectSingleNode("sourcebank_ref");
            if (el_sourcebankref == null) {
                // no reference to sourcebank, -> take internal one, but dtd disallows
                // it!?? TODO
                /*
					 * 2:27 PM] <felix.jost> aus ims qti sao: [2:27 PM] <felix.jost> 3.2.1
					 * <sourcebank_ref> Description: Identifies the objectbank to which
					 * the selection and ordering rules are to be applied. This objectbank
					 * may or may not be contained in the same <questestinterop> package.
					 * [2:27 PM] <felix.jost> aber dtd: [2:28 PM] <felix.jost> <!ELEMENT
					 * questestinterop (qticomment? , (objectbank | assessment | (section |
					 * item)+))>
					 */
                selectedItems = new ArrayList();
            } else {
                String sourceBankRef = el_sourcebankref.getText();
                Element objectBank = assessInstance.getResolver().getObjectBank(sourceBankRef);
                // traverse 1.: process "and" or "or" or "not" selection to get the
                // items, if existing, otherwise take all items
                // 2.: do the selection_number
                Element andornot_selection = (Element) el_selection.selectSingleNode("and_selection|or_selection|not_selection|selection_metadata");
                StringBuilder select_expr = new StringBuilder("//item");
                if (andornot_selection != null) {
                    // some criteria, extend above xpath to select only the appropriate
                    // elements
                    select_expr.append("[");
                    String elName = andornot_selection.getName();
                    ExpressionBuilder eb = QTIHelper.getExpressionBuilder(elName);
                    eb.buildXPathExpression(andornot_selection, select_expr, false, true);
                    select_expr.append("]");
                }
                selectedItems = objectBank.selectNodes(select_expr.toString());
                el_items.addAll(selectedItems);
            }
            Element el_selection_number = (Element) el_selection.selectSingleNode("selection_number");
            // --- 3. if selection_number exists, pick out some items
            if (el_selection_number != null) {
                String sNum = el_selection_number.getText();
                int num = new Integer(sNum).intValue();
                // now choose some x out of the items if selection_number exists
                List<Element> newList = new ArrayList<>();
                Random r = new Random();
                int size = el_items.size();
                // only four
                if (num > size)
                    num = size;
                for (int i = 0; i < num; i++) {
                    int n = r.nextInt(size--);
                    Element o = el_items.remove(n);
                    newList.add(o);
                }
                el_items = newList;
                /*
					 * pick out items -> remove unused items from section
					 */
                items.removeAll(el_items);
                for (Iterator iter = items.iterator(); iter.hasNext(); ) {
                    el_section.remove((Node) iter.next());
                }
            }
        // append found items to existing ones
        }
    }
    // <order order_type="Random"/>
    if (el_selordering != null) {
        Element el_order = (Element) el_selordering.selectSingleNode("order");
        if (el_order != null) {
            String order_type = el_order.attributeValue("order_type");
            if (order_type.equals("Random")) {
                Collections.shuffle(el_items);
            }
        }
    }
    // now wrap all item contexts
    itemContexts = new ArrayList<ItemContext>(10);
    for (Iterator<Element> iter = el_items.iterator(); iter.hasNext(); ) {
        Element item = iter.next();
        item.detach();
        ItemContext itc = new ItemContext();
        itc.setUp(assessInstance, item, sw);
        if (durationLimit != -1 && assessInstance.isSectionPage())
            itc.clearDurationLimit();
        itemContexts.add(itc);
    }
    // outcomesProcessing
    // <!ELEMENT section (qticomment? , duration? , qtimetadata* ,
    // objectives* , sectioncontrol* , sectionprecondition* ,
    // sectionpostcondition* ,
    // rubric* , presentation_material? ,
    // outcomes_processing* , sectionproc_extension? ,
    // sectionfeedback* , selection_ordering? ,
    // reference? , (itemref | item | sectionref | section)*)>
    // <!ELEMENT outcomes_processing (qticomment? , outcomes ,
    // objects_condition* , processing_parameter* , map_output* ,
    // outcomes_feedback_test*)>
    // <!ELEMENT outcomes (qticomment? , (decvar , interpretvar*)+)>
    // <!ELEMENT decvar (#PCDATA)>
    // <!ATTLIST decvar %I_VarName; .......cutvalue CDATA #IMPLIED >
    Element el_outpro = (Element) el_section.selectSingleNode("outcomes_processing");
    if (el_outpro != null) {
        // get the scoring model: we need it later for calculating the score
        // <!ENTITY % I_ScoreModel " scoremodel CDATA #IMPLIED">
        scoremodel = el_outpro.attributeValue("scoremodel");
        // may be null -> then assume SumOfScores
        // set the cutvalue if given (only variable score)
        cutvalue = QTIHelper.getIntAttribute(el_outpro, "outcomes/decvar[@varname='SCORE']", "cutvalue");
        List el_oft = el_outpro.selectNodes("outcomes_feedback_test");
        if (el_oft.size() != 0) {
            feedbacktesting = true;
        }
    }
}
Also used : Element(org.dom4j.Element) Objectives(org.olat.ims.qti.container.qtielements.Objectives) ArrayList(java.util.ArrayList) ExpressionBuilder(org.olat.ims.qti.process.elements.ExpressionBuilder) Random(java.util.Random) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

List (java.util.List)10 Element (org.dom4j.Element)10 ExpressionBuilder (org.olat.ims.qti.process.elements.ExpressionBuilder)10 ArrayList (java.util.ArrayList)4 Iterator (java.util.Iterator)4 Random (java.util.Random)4 Objectives (org.olat.ims.qti.container.qtielements.Objectives)2