1 /**general information
  2  *  
  3  *  word length >= 8 is not readable: make 8 midpoint between 1 and 16 letters per words
  4  *  
  5  *  sentence length >= 10 words ( actually depends on words length )
  6  *  	 (4.774193548387097, 89.5)
  7  *  
  8  *  vocabulary complexity: >=1 words not in list
  9  * 	avg. most frequent 5000 words: (0.5652173913043478, 0.9771428571428571)
 10  * 	avg. hard words: (0.0, 0.46111111111111114)
 11  *  
 12  *  nominal forms: noun-verb ratio = nouns/(nouns+verbs)
 13  *  	(0.23605442176870747, 0.8925366300366301)
 14  * 
 15  * sentence structure complexity: >= 2 
 16  * branching factor is the equivalent of the number of clause and phrase level elements within phrase structure tree of sentence
 17  *
 18  * Branching Factor: (5.064516129032258, 73.5)
 19  */
 20 
 21 //global readability intervals
 22 
 23 /** word length range */
 24 var MIN_WORDLEN = 1.0;							
 25 var MAX_WORDLEN = 16.0;	
 26 var NORM_WORDLEN = 1.0 / (MAX_WORDLEN - MIN_WORDLEN);
 27 
 28 /** sentence length range */
 29 var MIN_SENTLEN = 4.774193548387097; 			
 30 var MAX_SENTLEN = 89.5;	
 31 var NORM_SENTLEN = 1.0 / (MAX_SENTLEN - MIN_SENTLEN);
 32 
 33 /** vocabulary complexity range */
 34 var MIN_VOCCOMPL = 0.5652173913043478; 			
 35 var MAX_VOCCOMPL = 0.9771428571428571;	
 36 var NORM_VOCCOMPL = 1.0 / (MAX_VOCCOMPL - MIN_VOCCOMPL);
 37 
 38 /** nominal form range */
 39 var MIN_NOMFORM = 0.23605442176870747; 			
 40 var MAX_NOMFORM = 0.8925366300366301;
 41 var NORM_NOMFORM = 1.0 / (MAX_NOMFORM - MIN_NOMFORM);
 42 
 43 /** sentence structure complexity range */
 44 var MIN_SENTSTRUCTCOMPL = 5.064516129032258; 	
 45 var MAX_SENTSTRUCTCOMPL = 73.5;	
 46 var NORM_SENTSTRUCTCOMPL = 1.0 / (MAX_SENTSTRUCTCOMPL - MIN_SENTSTRUCTCOMPL);
 47 
 48 /**@class
 49  * SentenceDescription holds the sentence text and its calculated features
 50  * - normalizes the features
 51  * - store feature as (1 - normalized-feature-value) for display purposes
 52  * @param {number} wordLen readability-feature 'word length'
 53  * @param {number} sentLen readability-feature 'sentence length'
 54  * @param {number} vocCompl readability-feature 'vocabulary complexity'
 55  * @param {number} nomForm readability-feature 'nominal forms'
 56  * @param {number} sentStructCompl readability-feature 'sentence structure complexity'
 57  * @param {string} text sentence text
 58  */
 59 function SentenceDescription(wordLen, sentLen, vocCompl, nomForm, sentStructCompl, text)
 60 {
 61 	// word length
 62 	this.wordLen = (wordLen - MIN_WORDLEN) * NORM_WORDLEN;
 63 	if(this.wordLen < 0.0 || this.wordLen > 1.0){
 64 		if(this.wordLen < 0.0)
 65 			this.wordLen = 0.0;
 66 		else
 67 			this.wordLen = 1.0;
 68 	}
 69 	this.wordLen = 1.0 - this.wordLen;
 70 	
 71 	// sentence length
 72 	this.sentLen = (sentLen - MIN_SENTLEN) * NORM_SENTLEN;
 73 	if(this.sentLen < 0.0 || this.sentLen > 1.0){
 74 		if(this.sentLen < 0.0)
 75 			this.sentLen = 0.0;
 76 		else
 77 			this.sentLen = 1.0;
 78 	}
 79 	this.sentLen = 1.0 - this.sentLen;
 80 	
 81 	// vocabulary complexity
 82 	this.vocCompl = (vocCompl - MIN_VOCCOMPL) * NORM_VOCCOMPL;
 83 	if(this.vocCompl < 0.0 || this.vocCompl > 1.0){
 84 		if(this.vocCompl < 0.0)
 85 			this.vocCompl = 0.0;
 86 		else
 87 			this.vocCompl = 1.0;
 88 	}
 89 	this.vocCompl = 1.0 - this.vocCompl;
 90 	
 91 	// nominal forms
 92 	this.nomForm = (nomForm - MIN_NOMFORM) * NORM_NOMFORM;
 93 	if(this.nomForm < 0.0 || this.nomForm > 1.0){
 94 		if(this.nomForm < 0.0)
 95 			this.nomForm = 0.0;
 96 		else
 97 			this.nomForm = 1.0;
 98 	}
 99 	this.nomForm = 1.0 - this.nomForm;
100 	
101 	// sentence structure complexity
102 	this.sentStructCompl = (sentStructCompl - MIN_SENTSTRUCTCOMPL) * NORM_SENTSTRUCTCOMPL;
103 	if(this.sentStructCompl < 0.0 || this.sentStructCompl > 1.0){
104 		if(this.sentStructCompl < 0.0)
105 			this.sentStructCompl = 0.0;
106 		else
107 			this.sentStructCompl = 1.0;
108 	}
109 	this.sentStructCompl = 1.0 - this.sentStructCompl;
110 	
111 	this.text = text;
112 }
113 
114 /** returns the feature values of the sentence */
115 SentenceDescription.prototype.getProperties = function()
116 {
117 	var allProps = [ this.wordLen, this.sentLen, this.vocCompl, this.nomForm, this.sentStructCompl];
118 	return allProps;
119 };
120 
121 /** returns the sentence text */
122 SentenceDescription.prototype.getText = function()
123 {
124 	return this.text;
125 };
126