mainScript.js
/* Start Crawling and find the answer*/
Start Crawling and find the answer
Start Crawling and find the answer
function findAnswer() {
        probableAnswers = [];
        answerRelationName = "";
        argumentToMatch = "";
        answerArgumentIndex = "";
        var count = 0,
	    indexOfQuestionRelation = -1;
        originalQuestionObject = questionObject;
        originalAnswerObject = answerObject;
        answer = "";
        while (count < questionObject.length) {
            if (-1 !== questionObject[count].firstArgument.indexOf("@wh")) {
                indexOfQuestionRelation = count;
                answerRelationName = questionObject[count].relationName.split(":")[0];
                argumentToMatch = questionObject[count].secondArgument.split(":")[0];
                answerArgumentIndex = 0;
                break;
            }
            if (-1 !== questionObject[count].secondArgument.indexOf("@wh")) {
                indexOfQuestionRelation = count;
                answerRelationName = questionObject[count].relationName.split(":")[0];
                argumentToMatch = questionObject[count].firstArgument.split(":")[0];
                answerArgumentIndex = 1;
                break;
            }
            count++;
        }
        optimizer(checkIfQuestionIsCorrect, indexOfQuestionRelation);
        arrQuestionFirstArguments = [];
        arrQuestionSecondArguments = [];
        count = 0;
        while (count < questionObject.length) {
            questionObject[count].relationName = questionObject[count].relationName.split(":")[0];
            questionObject[count].firstArgument = questionObject[count].firstArgument.split(".")[0] !== "" ? questionObject[count].firstArgument.split(".")[0] : questionObject[count].firstArgument;
            questionObject[count].secondArgument = questionObject[count].secondArgument.split(".")[0] !== "" ? questionObject[count].secondArgument.split(".")[0] : questionObject[count].secondArgument;
            arrQuestionFirstArguments.push(questionObject[count].firstArgument);
            arrQuestionSecondArguments.push(questionObject[count].secondArgument);
            count++;
        }
        count = 0;
        var loop = 0, exit = 0;
        if (questionObject.length === 1) {
            for (var i = 0; i < answerObject.length; i++) {
                if (answerObject[i].relationName.split(":")[0] == answerRelationName) {
                    if (answerArgumentIndex === 0) {
                        if (answerObject[i].secondArgument.split(":")[0] == argumentToMatch) { answer = answerObject[i].firstArgument.split(":")[0]; }
                        else { if (arrQuestionFirstArguments.indexOf(answerObject[i].firstArgument.split(":")[0]) != -1) { probableAnswers.push(answerObject[i].firstArgument.split(":")[0]); } }
                    }
                    else {
                        if (answerObject[i].firstArgument.split(":")[0] == argumentToMatch) { answer = answerObject[i].secondArgument.split(":")[0]; }
                        else { if (arrQuestionSecondArguments.indexOf(answerObject[i].secondArgument.split(":")[0]) != -1) { probableAnswers.push(answerObject[i].secondArgument.split(":")[0]); } }
                    }
                }
                else { continue; }
            }
        }
        else {
            for (var i = 0; i < answerObject.length; i++) {
                if (answerObject[i].relationName.split(":")[0] == answerRelationName) {
                    if (answerArgumentIndex === 0) {
                        if (answerObject[i].secondArgument.split(":")[0] == argumentToMatch) { answer = answerObject[i].firstArgument.split(":")[0]; }
                        else { if (arrQuestionFirstArguments.indexOf(answerObject[i].firstArgument.split(":")[0]) != -1) { probableAnswers.push(answerObject[i].firstArgument.split(":")[0]); } }
                    }
                    else {
                        if (answerObject[i].firstArgument.split(":")[0] == argumentToMatch) { answer = answerObject[i].secondArgument.split(":")[0]; }
                        else { if (arrQuestionSecondArguments.indexOf(answerObject[i].secondArgument.split(":")[0]) != -1) { probableAnswers.push(answerObject[i].secondArgument.split(":")[0]); } }
                    }
                }
                else { continue; }
            }
        }
        optimizer(IsFullOrPartialMatch, indexOfQuestionRelation);
    }
function findAnswer ( ) { probableAnswers = [ ] ; answerRelationName = "" ; argumentToMatch = "" ; answerArgumentIndex = "" ; var count = 0 , indexOfQuestionRelation = - 1 ; originalQuestionObject = questionObject ; originalAnswerObject = answerObject ; answer = "" ; while ( count < questionObject . length ) { if ( - 1 !== questionObject [ count ] . firstArgument . indexOf ( "@wh" ) ) { indexOfQuestionRelation = count ; answerRelationName = questionObject [ count ] . relationName . split ( ":" ) [ 0 ] ; argumentToMatch = questionObject [ count ] . secondArgument . split ( ":" ) [ 0 ] ; answerArgumentIndex = 0 ; break ; } if ( - 1 !== questionObject [ count ] . secondArgument . indexOf ( "@wh" ) ) { indexOfQuestionRelation = count ; answerRelationName = questionObject [ count ] . relationName . split ( ":" ) [ 0 ] ; argumentToMatch = questionObject [ count ] . firstArgument . split ( ":" ) [ 0 ] ; answerArgumentIndex = 1 ; break ; } count ++ ; } optimizer ( checkIfQuestionIsCorrect , indexOfQuestionRelation ) ; arrQuestionFirstArguments = [ ] ; arrQuestionSecondArguments = [ ] ; count = 0 ; while ( count < questionObject . length ) { questionObject [ count ] . relationName = questionObject [ count ] . relationName . split ( ":" ) [ 0 ] ; questionObject [ count ] . firstArgument = questionObject [ count ] . firstArgument . split ( "." ) [ 0 ] !== "" ? questionObject [ count ] . firstArgument . split ( "." ) [ 0 ] : questionObject [ count ] . firstArgument ; questionObject [ count ] . secondArgument = questionObject [ count ] . secondArgument . split ( "." ) [ 0 ] !== "" ? questionObject [ count ] . secondArgument . split ( "." ) [ 0 ] : questionObject [ count ] . secondArgument ; arrQuestionFirstArguments . push ( questionObject [ count ] . firstArgument ) ; arrQuestionSecondArguments . push ( questionObject [ count ] . secondArgument ) ; count ++ ; } count = 0 ; var loop = 0 , exit = 0 ; if ( questionObject . length === 1 ) { for ( var i = 0 ; i < answerObject . length ; i ++ ) { if ( answerObject [ i ] . relationName . split ( ":" ) [ 0 ] == answerRelationName ) { if ( answerArgumentIndex === 0 ) { if ( answerObject [ i ] . secondArgument . split ( ":" ) [ 0 ] == argumentToMatch ) { answer = answerObject [ i ] . firstArgument . split ( ":" ) [ 0 ] ; } else { if ( arrQuestionFirstArguments . indexOf ( answerObject [ i ] . firstArgument . split ( ":" ) [ 0 ] ) != - 1 ) { probableAnswers . push ( answerObject [ i ] . firstArgument . split ( ":" ) [ 0 ] ) ; } } } else { if ( answerObject [ i ] . firstArgument . split ( ":" ) [ 0 ] == argumentToMatch ) { answer = answerObject [ i ] . secondArgument . split ( ":" ) [ 0 ] ; } else { if ( arrQuestionSecondArguments . indexOf ( answerObject [ i ] . secondArgument . split ( ":" ) [ 0 ] ) != - 1 ) { probableAnswers . push ( answerObject [ i ] . secondArgument . split ( ":" ) [ 0 ] ) ; } } } } else { continue ; } } } else { for ( var i = 0 ; i < answerObject . length ; i ++ ) { if ( answerObject [ i ] . relationName . split ( ":" ) [ 0 ] == answerRelationName ) { if ( answerArgumentIndex === 0 ) { if ( answerObject [ i ] . secondArgument . split ( ":" ) [ 0 ] == argumentToMatch ) { answer = answerObject [ i ] . firstArgument . split ( ":" ) [ 0 ] ; } else { if ( arrQuestionFirstArguments . indexOf ( answerObject [ i ] . firstArgument . split ( ":" ) [ 0 ] ) != - 1 ) { probableAnswers . push ( answerObject [ i ] . firstArgument . split ( ":" ) [ 0 ] ) ; } } } else { if ( answerObject [ i ] . firstArgument . split ( ":" ) [ 0 ] == argumentToMatch ) { answer = answerObject [ i ] . secondArgument . split ( ":" ) [ 0 ] ; } else { if ( arrQuestionSecondArguments . indexOf ( answerObject [ i ] . secondArgument . split ( ":" ) [ 0 ] ) != - 1 ) { probableAnswers . push ( answerObject [ i ] . secondArgument . split ( ":" ) [ 0 ] ) ; } } } } else { continue ; } } } optimizer ( IsFullOrPartialMatch , indexOfQuestionRelation ) ; }
Start Crawling and find the answer
Start Crawling and find the answer
/* 
        If index of Question relation = -1, means no question is asked in question UNL i.e., it is not 
        having any '@wh' attribute.
        */ /*
       Call 'Optimizer' to check if question is asked or not
       */ // refine question unl for matching with answer unl
 // find an answer
 // Match second argument
 // Start finding answer
 // Match second argument
 // End finding answer
 /*
        Call 'Optimizer' to check if its a full/ partial match
        */