this.relation2Pronoun = function(ref) {
if (!ref) {
return '';
}
var relation;
var words = ref.split(" ");
switch(words[0]) {
case "your":
case "my":
case "his":
case "her":
case "their":
words.shift();
relation = words.join(" ");
break;
default:
relation = ref;
}
var gender = relation2Gender(relation);
switch(gender){
case "male":
return "he";
case "female":
return "she";
}
switch (relation) {
case "parents":
case "families":
case "siblings":
case "brothers":
case "sisters":
case "children":
case "sons":
case "daughters":
case "friends":
case "boyfriends":
case "girlfriends":
case "colleagues":
case "pets":
case "dogs":
case "cats":
return "they";
default:
return '';
}
}; |
this.runPS = function( ) {
if (!this.psOn){
return '';
}
this.psOn = 0;
var results;
var condition;
for (var i in this.ps){
condition = '"'+this.ps[i].condition+'"';
var isTrue;
if (this.ps[i].condition === ""){
isTrue = true;
}
else {
isTrue = eval('(' + this.ps[i].condition + ')');
}
if (isTrue){
results = this.ps[i].output;
results = results.replace(/{/g,'<');
results = results.replace(/}/g,'>');
if (this.occurrences(results, '^') > 0){
if (this.occurrences(results, '^') === this.occurrences(results, ';')){
results = results.replace(/\^/g,'');
results = results.replace(/;/g,'');
}
}
this.ps.splice(i,1);
break;
}
}
if (this.psTMP.length > 0) {
this.ps = this.uniquePS(this.ps.concat(this.psTMP));
this.psTMP = [];
}
return results;
}; |
this.scGetDate = function(days) {
var d = new Date(new Date().getTime() + 8 * 3600 * 1000);
if(!days) {
days = "0";
}
d.setDate(d.getDate() + parseInt(days));
r = (d.getMonth() + 1) + "月" + d.getDate() + "日"
return r;
}; |
this.scGetDay = function(days, months, years) {
var wd = {
1:"星期一",
2:"星期二",
3:"星期三",
4:"星期四",
5:"星期五",
6:"星期六",
0:"星期日"
};
var d = new Date();
var m = d.getMonth();
if(months) {
m = m + parseInt(months);
}
var y = d.getFullYear();
if(years) {
y = y + parseInt(years);
}
var dt = d.getDate();
if(days) {
dt = dt + parseInt(days);
}
d.setFullYear(y, m, dt);
r = wd[d.getDay()];
return r;
}; |
this.scWord2num = function(chnStr) {
var chnNumChar = {
零:0,
一:1,
二:2,
两:2,
三:3,
四:4,
五:5,
六:6,
七:7,
八:8,
九:9,
壹:1,
贰:2,
叁:3,
肆:4,
伍:5,
陆:6,
柒:7,
捌:8,
玖:9
};
var chnNameValue = {
十:10,
百:100,
千:1000,
万:10000,
亿:100000000,
拾:10,
佰:100,
仟:1000
};
chnStr = chnStr.replace(/\s/g,'');
if(chnStr.length >= 2 &&
(chnStr.indexOf('十') == -1 && chnStr.indexOf('百') == -1
&& chnStr.indexOf('千') == -1 && chnStr.indexOf('万') == -1
&& chnStr.indexOf('亿') == -1 && chnStr.indexOf('拾') == -1
&& chnStr.indexOf('佰') == -1 && chnStr.indexOf('仟') == -1)
) {
var str = "";
for(var i = 0; i < chnStr.length; i++) {
var num = chnNumChar[chnStr[i]];
str += num;
}
// console.log(str);
return str;
} else if(chnStr.charAt(0) >= '0' && chnStr.charAt(0) <= '9') {
// console.log(chnStr);
return chnStr;
}
var rtn = 0;
var section = 0;
var number = 0;
var secUnit = false;
var str;
var fchar = chnStr.charAt(0);
if(fchar == '十' || fchar == '百' || fchar == '千' || fchar == '万' || fchar== '亿') {
str = ("一"+chnStr).split('');
} else {
str = chnStr.split('');
}
for(var i = 0; i < str.length; i++){
var num = chnNumChar[str[i]];
if(typeof num !== 'undefined'){
number = num;
if(i === str.length - 1){
section += number;
}
}else{
var unit = chnNameValue[str[i]];
if(unit == 10000 || unit == 100000000) {
section = (section + number) * unit;
rtn += section;
section = 0;
} else {
section += (number * unit);
}
number = 0;
}
}
return rtn + section;
}; |
this.sentenceAudio = function(word, index) {
if (word === undefined) {
return 'acox sentenceaudio JSError';
}
if (index === undefined) {
index = 0;
}
var url = 'http://acobot.com/api/swa/'+word+'/'+index;
return sraix(url);
}; |
this.sentenceAudioRand = function(prev) {
if (prev === undefined){
prev = 0;
}
var url = 'http://acobot.com/api/swa_rand/' + prev;
return sraix(url);
}; |
this.setAdQuery = function( ) {
this.adCount ++;
this.adQuery = this.msgCount;
}; |
this.setAge = function(str) {
var n = parseFloat(str);
if (this.isNumber(n)) {
this.age = n;
var d = new Date();
this.ageDate = d.getTime();
if(this.birth) {
this.birth.year = d.getFullYear() - n;
}
return true;
}
else {
return false;
}
}; |
this.setBirthday = function(day, month, year) {
if (!day){
return false;
}
// if a single parameter is provided, try to parse it into day, month and year
if (month === undefined){
return this.setBirthdayByDate(day);
}
if (this.birth.set(day, month, year)) {
var d = new Date();
var thisYear = d.getFullYear();
var youngest = thisYear-4;
var oldest = thisYear-100;
if (year < youngest && year > oldest){
this.birth.year = year;
this.age = thisYear -year;
this.ageDate = d;
}
return true;
}
else {
return false;
}
}; |