/** * Populates finalPostObjList * Adds excerpt node element to postList * * 1. Search for all coded excerpt nodes * 2. For each node, find the corresponding postObj: * a. Iterate for a postObj whose 'content' attribute contains the coded_excerpt * if there are none, or there are two: * b. Search upward through parents of coded_excerpt until you find a single element with 'post-(id)' or '(nonnumeric)(id)' * c. If there are two, check if one of them fits both categories (implement this later) */ function associatePostObjWithExcerptNode(postList) { var excerptNodes = getChildNodesWithCondition(document, function(childNode) { var data = childNode.data; return data && data.match && data.match(/[\+\-\*]{3}/g); }); for(var i=0; i= .90 || longestCommonSubLen / trimmedData.length >= .90) { matchingPostObjs.push(postObj); } } //If we have a single matching postObj, associate it with the current excerptNode if(matchingPostObjs.length === 1) { return matchingPostObjs[0]; } return null; } /** * Searches upward through parents of excerptNode to discover a * single postNode with 'post-(id)' or '(nonnumeric)(id)' * Then associates the corresponding postObj with excerptNode */ function findCorrespondingPostObjById(excerptNode, postList) { var matchingPostObjs = []; var success = false; for(var k=0; k matchingPostObj.pos) { candidatePos = matchingPostObj.pos; closestObj = matchingPostObj.postObj; } } return closestObj; } /** * Halts on first success */ function getFirstElderWithCondition(node, conditionFunc) { //breadth first search var queue = []; queue.push(node); //while Q is not empty var pos = 0; while(queue.length > 0) { var node = queue.shift(); //check the condition (which is the point of the search) if(conditionFunc(node)) { return {node: node, pos: pos}; } var adjacentNodes = []; var parentNode = node.parentNode; if(parentNode) { adjacentNodes.push(parentNode); adjacentNodes = adjacentNodes.concat(getSiblings(parentNode)); } //for all edges from v to w in G.adjacentEdges(v) do for(var i=0; i longestCommonSubstring){ longestCommonSubstring = table[i+1][j+1]; } } else { table[i+1][j+1] = 0; } } } return longestCommonSubstring; } var finalPostObjList = []; associatePostObjWithExcerptNode(postTitlesAndUrls); addDivsToCodedExcerpts(postTitlesAndUrls);