Prefix private variables with an underscore. Fixes #72

This commit is contained in:
mossroy 2014-03-21 13:46:57 +01:00
parent 2d4e949367
commit 9e9d9ea45b
5 changed files with 1639 additions and 1640 deletions

View File

@ -58,7 +58,7 @@ define(function(require) {
equal(titleList.length, 4, "4 titles found, as requested"); equal(titleList.length, 4, "4 titles found, as requested");
var indexAbraham = -1; var indexAbraham = -1;
for (var i = 0; i < titleList.length; i++) { for (var i = 0; i < titleList.length; i++) {
if (titleList[i] && titleList[i].name === "Abraham") { if (titleList[i] && titleList[i]._name === "Abraham") {
indexAbraham = i; indexAbraham = i;
} }
} }
@ -66,10 +66,10 @@ define(function(require) {
var firstTitleName = "not found"; var firstTitleName = "not found";
var secondTitleName = "not found"; var secondTitleName = "not found";
if (titleList.length >= 1 && titleList[0]) { if (titleList.length >= 1 && titleList[0]) {
firstTitleName = titleList[0].name; firstTitleName = titleList[0]._name;
} }
if (titleList.length >= 2 && titleList[1]) { if (titleList.length >= 2 && titleList[1]) {
secondTitleName = titleList[1].name; secondTitleName = titleList[1]._name;
} }
equal(firstTitleName, "Abbasid_Caliphate", "First article name is 'Abbasid_Caliphate'"); equal(firstTitleName, "Abbasid_Caliphate", "First article name is 'Abbasid_Caliphate'");
equal(secondTitleName, "Abortion", "Second article name is 'Abortion'"); equal(secondTitleName, "Abortion", "Second article name is 'Abortion'");
@ -85,10 +85,10 @@ define(function(require) {
var firstTitleName = "not found"; var firstTitleName = "not found";
var secondTitleName = "not found"; var secondTitleName = "not found";
if (titleList.length >= 1 && titleList[0]) { if (titleList.length >= 1 && titleList[0]) {
firstTitleName = titleList[0].name; firstTitleName = titleList[0]._name;
} }
if (titleList.length >= 2 && titleList[1]) { if (titleList.length >= 2 && titleList[1]) {
secondTitleName = titleList[1].name; secondTitleName = titleList[1]._name;
} }
equal(firstTitleName, "Amazon_River", "First article name is 'Amazon_River'"); equal(firstTitleName, "Amazon_River", "First article name is 'Amazon_River'");
equal(secondTitleName, "American_Civil_War", "Second article name is 'American_Civil_War'"); equal(secondTitleName, "American_Civil_War", "Second article name is 'American_Civil_War'");
@ -100,19 +100,19 @@ define(function(require) {
// Create a title instance for the Article 'Abraham' // Create a title instance for the Article 'Abraham'
var titleAbraham = new evopediaTitle.Title(); var titleAbraham = new evopediaTitle.Title();
titleAbraham.archive = localArchive; titleAbraham._archive = localArchive;
titleAbraham.articleLength = 10071; titleAbraham._articleLength = 10071;
titleAbraham.blockOffset = 127640; titleAbraham._blockOffset = 127640;
titleAbraham.blockStart = 2364940; titleAbraham._blockStart = 2364940;
titleAbraham.fileNr = 0; titleAbraham._fileNr = 0;
titleAbraham.name = "Abraham"; titleAbraham._name = "Abraham";
titleAbraham.titleOffset = 57; titleAbraham._titleOffset = 57;
asyncTest("check getTitleByName with accents : Diego Velázquez", function() { asyncTest("check getTitleByName with accents : Diego Velázquez", function() {
expect(2); expect(2);
var callbackFunction = function(title) { var callbackFunction = function(title) {
ok(title !== null, "Title found"); ok(title !== null, "Title found");
equal(title.name, "Diego_Velázquez", "Name of the title is correct"); equal(title._name, "Diego_Velázquez", "Name of the title is correct");
start(); start();
}; };
localArchive.getTitleByName("Diego_Velázquez", callbackFunction); localArchive.getTitleByName("Diego_Velázquez", callbackFunction);
@ -121,7 +121,7 @@ define(function(require) {
expect(2); expect(2);
var callbackFunction = function(title) { var callbackFunction = function(title) {
ok(title !== null, "Title found"); ok(title !== null, "Title found");
equal(title.name, "Hundred_Years'_War", "Name of the title is correct"); equal(title._name, "Hundred_Years'_War", "Name of the title is correct");
start(); start();
}; };
localArchive.getTitleByName("Hundred_Years'_War", callbackFunction); localArchive.getTitleByName("Hundred_Years'_War", callbackFunction);
@ -159,7 +159,7 @@ define(function(require) {
}; };
var callbackTitleFound = function(title) { var callbackTitleFound = function(title) {
ok(title !== null, "Title found"); ok(title !== null, "Title found");
equal(title.name, "AIDS", "Name of the title is correct"); equal(title._name, "AIDS", "Name of the title is correct");
localArchive.readArticle(title, callbackArticleRead); localArchive.readArticle(title, callbackArticleRead);
}; };
localArchive.getTitleByName("AIDS", callbackTitleFound); localArchive.getTitleByName("AIDS", callbackTitleFound);
@ -308,13 +308,13 @@ define(function(require) {
var titleAlps = null; var titleAlps = null;
for (var i=0; i<titleList.length; i++) { for (var i=0; i<titleList.length; i++) {
var title = titleList[i]; var title = titleList[i];
if (title.name === "Danube") { if (title._name === "Danube") {
titleDanube = title; titleDanube = title;
} }
else if (title.name === "Paris") { else if (title._name === "Paris") {
titleParis = title; titleParis = title;
} }
else if (title.name === "Alps") { else if (title._name === "Alps") {
titleAlps = title; titleAlps = title;
} }
} }
@ -348,7 +348,7 @@ define(function(require) {
var titleLondon = null; var titleLondon = null;
for (var i=0; i<titleList.length; i++) { for (var i=0; i<titleList.length; i++) {
var title = titleList[i]; var title = titleList[i];
if (title.name === "London") { if (title._name === "London") {
titleLondon = title; titleLondon = title;
} }
} }
@ -374,7 +374,7 @@ define(function(require) {
var titleAmsterdam = null; var titleAmsterdam = null;
for (var i=0; i<titleList.length; i++) { for (var i=0; i<titleList.length; i++) {
var title = titleList[i]; var title = titleList[i];
if (title.name === "Amsterdam") { if (title._name === "Amsterdam") {
titleAmsterdam = title; titleAmsterdam = title;
} }
} }
@ -397,7 +397,7 @@ define(function(require) {
expect(2); expect(2);
var callbackRandomTitleFound = function(title) { var callbackRandomTitleFound = function(title) {
ok(title !== null, "One title should be found"); ok(title !== null, "One title should be found");
ok(title.name !== null, "The random title should have a name" ); ok(title._name !== null, "The random title should have a name" );
start(); start();
}; };

View File

@ -62,7 +62,7 @@ define(function(require) {
return false; return false;
}); });
$('#prefix').on('keyup', function(e) { $('#prefix').on('keyup', function(e) {
if (localArchive !== null && localArchive.titleFile !== null) { if (localArchive !== null && localArchive._titleFile !== null) {
onKeyUpPrefix(e); onKeyUpPrefix(e);
$('#geolocationProgress').hide(); $('#geolocationProgress').hide();
} }
@ -322,7 +322,7 @@ define(function(require) {
$('#searchingForTitles').show(); $('#searchingForTitles').show();
$('#configuration').hide(); $('#configuration').hide();
$('#articleContent').empty(); $('#articleContent').empty();
if (localArchive !== null && localArchive.titleFile !== null) { if (localArchive !== null && localArchive._titleFile !== null) {
localArchive.findTitlesWithPrefix(prefix.trim(), MAX_SEARCH_RESULT_SIZE, populateListOfTitles); localArchive.findTitlesWithPrefix(prefix.trim(), MAX_SEARCH_RESULT_SIZE, populateListOfTitles);
} else { } else {
$('#searchingForTitles').hide(); $('#searchingForTitles').hide();
@ -404,7 +404,7 @@ define(function(require) {
$("#titleList").empty(); $("#titleList").empty();
findTitleFromTitleIdAndLaunchArticleRead(titleId); findTitleFromTitleIdAndLaunchArticleRead(titleId);
var title = evopediaTitle.Title.parseTitleId(localArchive, titleId); var title = evopediaTitle.Title.parseTitleId(localArchive, titleId);
pushBrowserHistoryState(title.name); pushBrowserHistoryState(title._name);
$("#prefix").val(""); $("#prefix").val("");
return false; return false;
} }
@ -416,12 +416,12 @@ define(function(require) {
* @param {type} titleId * @param {type} titleId
*/ */
function findTitleFromTitleIdAndLaunchArticleRead(titleId) { function findTitleFromTitleIdAndLaunchArticleRead(titleId) {
if (localArchive.dataFiles && localArchive.dataFiles.length > 0) { if (localArchive._dataFiles && localArchive._dataFiles.length > 0) {
var title = evopediaTitle.Title.parseTitleId(localArchive, titleId); var title = evopediaTitle.Title.parseTitleId(localArchive, titleId);
$("#articleName").html(title.name); $("#articleName").html(title._name);
$("#readingArticle").show(); $("#readingArticle").show();
$("#articleContent").html(""); $("#articleContent").html("");
if (title.fileNr === 255) { if (title._fileNr === 255) {
localArchive.resolveRedirect(title, readArticle); localArchive.resolveRedirect(title, readArticle);
} }
else { else {
@ -438,7 +438,7 @@ define(function(require) {
* @param {type} title * @param {type} title
*/ */
function readArticle(title) { function readArticle(title) {
if (title.fileNr === 255) { if (title._fileNr === 255) {
localArchive.resolveRedirect(title, readArticle); localArchive.resolveRedirect(title, readArticle);
} }
else { else {
@ -571,7 +571,7 @@ define(function(require) {
$('#configuration').hide(); $('#configuration').hide();
$('#titleList').hide(); $('#titleList').hide();
$('#articleContent').empty(); $('#articleContent').empty();
if (localArchive !== null && localArchive.titleFile !== null) { if (localArchive !== null && localArchive._titleFile !== null) {
var longitude = $('#longitude').val(); var longitude = $('#longitude').val();
var latitude = $('#latitude').val(); var latitude = $('#latitude').val();
var maxDistance = $('#maxDistance').val(); var maxDistance = $('#maxDistance').val();
@ -659,7 +659,7 @@ define(function(require) {
alert("Error finding random article."); alert("Error finding random article.");
} }
else { else {
$("#articleName").html(title.name); $("#articleName").html(title._name);
$("#readingArticle").show(); $("#readingArticle").show();
$("#articleContent").html(""); $("#articleContent").html("");
readArticle(title); readArticle(title);

View File

@ -49,15 +49,15 @@ define(function(require) {
* LocalArchive class : defines a wikipedia dump on the filesystem * LocalArchive class : defines a wikipedia dump on the filesystem
*/ */
function LocalArchive() { function LocalArchive() {
this.dataFiles = new Array(); this._dataFiles = new Array();
this.coordinateFiles = new Array(); this._coordinateFiles = new Array();
this.titleFile = null; this._titleFile = null;
this.mathIndexFile = null; this._mathIndexFile = null;
this.mathDataFile = null; this._mathDataFile = null;
this.date = null; this._date = null;
this.language = null; this._language = null;
this.titleSearchFile = null; this._titleSearchFile = null;
this.normalizedTitles = true; this._normalizedTitles = true;
}; };
@ -71,12 +71,12 @@ define(function(require) {
LocalArchive.prototype.readTitleFilesFromStorage = function(storage, directory) { LocalArchive.prototype.readTitleFilesFromStorage = function(storage, directory) {
var currentLocalArchiveInstance = this; var currentLocalArchiveInstance = this;
storage.get(directory + 'titles.idx').then(function(file) { storage.get(directory + 'titles.idx').then(function(file) {
currentLocalArchiveInstance.titleFile = file; currentLocalArchiveInstance._titleFile = file;
}, function(error) { }, function(error) {
alert("Error reading title file in directory " + directory + " : " + error); alert("Error reading title file in directory " + directory + " : " + error);
}); });
storage.get(directory + 'titles_search.idx').then(function(file) { storage.get(directory + 'titles_search.idx').then(function(file) {
currentLocalArchiveInstance.titleSearchFile = file; currentLocalArchiveInstance._titleSearchFile = file;
}, function(error) { }, function(error) {
// Do nothing : this file is not mandatory in an archive // Do nothing : this file is not mandatory in an archive
}); });
@ -132,7 +132,7 @@ define(function(require) {
} }
storage.get(directory + 'coordinates_' + prefixedFileNumber storage.get(directory + 'coordinates_' + prefixedFileNumber
+ '.idx').then(function(file) { + '.idx').then(function(file) {
currentLocalArchiveInstance.coordinateFiles[index - 1] = file; currentLocalArchiveInstance._coordinateFiles[index - 1] = file;
currentLocalArchiveInstance.readCoordinateFilesFromStorage(storage, directory, currentLocalArchiveInstance.readCoordinateFilesFromStorage(storage, directory,
index + 1); index + 1);
}, function(error) { }, function(error) {
@ -179,14 +179,14 @@ define(function(require) {
if (normalizedTitlesRegex.exec(metadata)) { if (normalizedTitlesRegex.exec(metadata)) {
var normalizedTitlesInt = normalizedTitlesRegex.exec(metadata)[1]; var normalizedTitlesInt = normalizedTitlesRegex.exec(metadata)[1];
if (normalizedTitlesInt === "0") { if (normalizedTitlesInt === "0") {
currentLocalArchiveInstance.normalizedTitles = false; currentLocalArchiveInstance._normalizedTitles = false;
} }
else { else {
currentLocalArchiveInstance.normalizedTitles = true; currentLocalArchiveInstance._normalizedTitles = true;
} }
} }
else { else {
currentLocalArchiveInstance.normalizedTitles = true; currentLocalArchiveInstance._normalizedTitles = true;
} }
}; };
reader.readAsText(file); reader.readAsText(file);
@ -199,8 +199,8 @@ define(function(require) {
LocalArchive.prototype.initializeFromArchiveFiles = function(archiveFiles) { LocalArchive.prototype.initializeFromArchiveFiles = function(archiveFiles) {
var dataFileRegex = /^wikipedia_(\d\d).dat$/; var dataFileRegex = /^wikipedia_(\d\d).dat$/;
var coordinateFileRegex = /^coordinates_(\d\d).idx$/; var coordinateFileRegex = /^coordinates_(\d\d).idx$/;
this.dataFiles = new Array(); this._dataFiles = new Array();
this.coordinateFiles = new Array(); this._coordinateFiles = new Array();
for (var i=0; i<archiveFiles.length; i++) { for (var i=0; i<archiveFiles.length; i++) {
var file = archiveFiles[i]; var file = archiveFiles[i];
if (file) { if (file) {
@ -208,28 +208,28 @@ define(function(require) {
this.readMetadataFile(file); this.readMetadataFile(file);
} }
else if (file.name === "titles.idx") { else if (file.name === "titles.idx") {
this.titleFile = file; this._titleFile = file;
} }
else if (file.name === "titles_search.idx") { else if (file.name === "titles_search.idx") {
this.titleSearchFile = file; this._titleSearchFile = file;
} }
else if (file.name === "math.idx") { else if (file.name === "math.idx") {
this.mathIndexFile = file; this._mathIndexFile = file;
} }
else if (file.name === "math.dat") { else if (file.name === "math.dat") {
this.mathDataFile = file; this._mathDataFile = file;
} }
else { else {
var coordinateFileNr = coordinateFileRegex.exec(file.name); var coordinateFileNr = coordinateFileRegex.exec(file.name);
if (coordinateFileNr && coordinateFileNr.length > 0) { if (coordinateFileNr && coordinateFileNr.length > 0) {
var intFileNr = 1 * coordinateFileNr[1]; var intFileNr = 1 * coordinateFileNr[1];
this.coordinateFiles[intFileNr - 1] = file; this._coordinateFiles[intFileNr - 1] = file;
} }
else { else {
var dataFileNr = dataFileRegex.exec(file.name); var dataFileNr = dataFileRegex.exec(file.name);
if (dataFileNr && dataFileNr.length > 0) { if (dataFileNr && dataFileNr.length > 0) {
var intFileNr = 1 * dataFileNr[1]; var intFileNr = 1 * dataFileNr[1];
this.dataFiles[intFileNr] = file; this._dataFiles[intFileNr] = file;
} }
} }
} }
@ -341,12 +341,12 @@ define(function(require) {
var normalize = this.getNormalizeFunction(); var normalize = this.getNormalizeFunction();
var normalizedTitleName = normalize(titleName); var normalizedTitleName = normalize(titleName);
titleIterators.findPrefixOffset(this.titleFile, titleName, normalize).then(function(offset) { titleIterators.findPrefixOffset(this._titleFile, titleName, normalize).then(function(offset) {
var iterator = new titleIterators.SequentialTitleIterator(that, offset); var iterator = new titleIterators.SequentialTitleIterator(that, offset);
function check(title) { function check(title) {
if (title === null || normalize(title.name) !== normalizedTitleName) { if (title === null || normalize(title._name) !== normalizedTitleName) {
return null; return null;
} else if (title.name === titleName) { } else if (title._name === titleName) {
return title; return title;
} else { } else {
return iterator.advance().then(check); return iterator.advance().then(check);
@ -362,9 +362,9 @@ define(function(require) {
*/ */
LocalArchive.prototype.getRandomTitle = function(callbackFunction) { LocalArchive.prototype.getRandomTitle = function(callbackFunction) {
var that = this; var that = this;
var offset = Math.floor(Math.random() * this.titleFile.size); var offset = Math.floor(Math.random() * this._titleFile.size);
jQuery.when().then(function() { jQuery.when().then(function() {
return util.readFileSlice(that.titleFile, offset, return util.readFileSlice(that._titleFile, offset,
offset + titleIterators.MAX_TITLE_LENGTH).then(function(byteArray) { offset + titleIterators.MAX_TITLE_LENGTH).then(function(byteArray) {
// Let's find the next newLine // Let's find the next newLine
var newLineIndex = 0; var newLineIndex = 0;
@ -389,7 +389,7 @@ define(function(require) {
var normalize = this.getNormalizeFunction(); var normalize = this.getNormalizeFunction();
prefix = normalize(prefix); prefix = normalize(prefix);
titleIterators.findPrefixOffset(this.titleFile, prefix, normalize).then(function(offset) { titleIterators.findPrefixOffset(this._titleFile, prefix, normalize).then(function(offset) {
var iterator = new titleIterators.SequentialTitleIterator(that, offset); var iterator = new titleIterators.SequentialTitleIterator(that, offset);
function addNext() { function addNext() {
if (titles.length >= maxSize) { if (titles.length >= maxSize) {
@ -399,7 +399,7 @@ define(function(require) {
if (title === null) if (title === null)
return jQuery.Deferred().resolve(titles, maxSize); return jQuery.Deferred().resolve(titles, maxSize);
// check whether this title really starts with the prefix // check whether this title really starts with the prefix
var name = normalize(title.name); var name = normalize(title._name);
if (name.length < prefix.length || name.substring(0, prefix.length) !== prefix) if (name.length < prefix.length || name.substring(0, prefix.length) !== prefix)
return jQuery.Deferred().resolve(titles, maxSize); return jQuery.Deferred().resolve(titles, maxSize);
titles.push(title); titles.push(title);
@ -422,28 +422,28 @@ define(function(require) {
var dataFile = null; var dataFile = null;
var prefixedFileNumber = ""; var prefixedFileNumber = "";
if (title.fileNr < 10) { if (title._fileNr < 10) {
prefixedFileNumber = "0" + title.fileNr; prefixedFileNumber = "0" + title._fileNr;
} else { } else {
prefixedFileNumber = title.fileNr; prefixedFileNumber = title._fileNr;
} }
var expectedFileName = "wikipedia_" + prefixedFileNumber + ".dat"; var expectedFileName = "wikipedia_" + prefixedFileNumber + ".dat";
// Find the good dump file // Find the good dump file
for (var i = 0; i < this.dataFiles.length; i++) { for (var i = 0; i < this._dataFiles.length; i++) {
var fileName = this.dataFiles[i].name; var fileName = this._dataFiles[i].name;
// Check if the fileName ends with the expected file name (in case // Check if the fileName ends with the expected file name (in case
// of DeviceStorage usage, the fileName is prefixed by the // of DeviceStorage usage, the fileName is prefixed by the
// directory) // directory)
if (fileName.match(expectedFileName + "$") == expectedFileName) { if (fileName.match(expectedFileName + "$") == expectedFileName) {
dataFile = this.dataFiles[i]; dataFile = this._dataFiles[i];
} }
} }
if (!dataFile) { if (!dataFile) {
// TODO can probably be replaced by some error handler at window level // TODO can probably be replaced by some error handler at window level
alert("Oops : some files seem to be missing in your archive. Please report this problem to us by email (see About section), with the names of the archive and article, and the following info : " alert("Oops : some files seem to be missing in your archive. Please report this problem to us by email (see About section), with the names of the archive and article, and the following info : "
+ "File number " + title.fileNr + " not found"); + "File number " + title._fileNr + " not found");
throw new Error("File number " + title.fileNr + " not found"); throw new Error("File number " + title._fileNr + " not found");
} else { } else {
var reader = new FileReader(); var reader = new FileReader();
// Read the article in the dataFile, starting with a chunk of CHUNK_SIZE // Read the article in the dataFile, starting with a chunk of CHUNK_SIZE
@ -486,11 +486,11 @@ define(function(require) {
case "result": case "result":
var htmlArticles = event.data.msg; var htmlArticles = event.data.msg;
// Start reading at offset, and keep length characters // Start reading at offset, and keep length characters
var htmlArticle = htmlArticles.substring(title.blockOffset, var htmlArticle = htmlArticles.substring(title._blockOffset,
title.blockOffset + title.articleLength); title._blockOffset + title._articleLength);
if (htmlArticle.length >= title.articleLength) { if (htmlArticle.length >= title._articleLength) {
// Keep only length characters // Keep only length characters
htmlArticle = htmlArticle.substring(0, title.articleLength); htmlArticle = htmlArticle.substring(0, title._articleLength);
// Decode UTF-8 encoding // Decode UTF-8 encoding
htmlArticle = decodeURIComponent(escape(htmlArticle)); htmlArticle = decodeURIComponent(escape(htmlArticle));
callbackFunction(title, htmlArticle); callbackFunction(title, htmlArticle);
@ -522,7 +522,7 @@ define(function(require) {
callbackFunction("Error : " + e); callbackFunction("Error : " + e);
} }
}; };
var blob = dataFile.slice(title.blockStart, title.blockStart var blob = dataFile.slice(title._blockStart, title._blockStart
+ readLength); + readLength);
// Read in the image file as a binary string. // Read in the image file as a binary string.
@ -539,9 +539,9 @@ define(function(require) {
LocalArchive.prototype.loadMathImage = function(hexString, callbackFunction) { LocalArchive.prototype.loadMathImage = function(hexString, callbackFunction) {
var entrySize = 16 + 4 + 4; var entrySize = 16 + 4 + 4;
var lo = 0; var lo = 0;
var hi = this.mathIndexFile.size / entrySize; var hi = this._mathIndexFile.size / entrySize;
var mathDataFile = this.mathDataFile; var mathDataFile = this._mathDataFile;
this.findMathDataPosition(hexString, lo, hi, function(pos, length) { this.findMathDataPosition(hexString, lo, hi, function(pos, length) {
var reader = new FileReader(); var reader = new FileReader();
@ -578,7 +578,7 @@ define(function(require) {
alert('Math image file read cancelled'); alert('Math image file read cancelled');
}; };
var mid = Math.floor((lo + hi) / 2); var mid = Math.floor((lo + hi) / 2);
var blob = this.mathIndexFile.slice(mid * entrySize, (mid + 1) * entrySize); var blob = this._mathIndexFile.slice(mid * entrySize, (mid + 1) * entrySize);
var currentLocalArchiveInstance = this; var currentLocalArchiveInstance = this;
reader.onload = function(e) { reader.onload = function(e) {
var byteArray = new Uint8Array(e.target.result); var byteArray = new Uint8Array(e.target.result);
@ -619,20 +619,20 @@ define(function(require) {
if (byteArray.length === 0) { if (byteArray.length === 0) {
// TODO can probably be replaced by some error handler at window level // TODO can probably be replaced by some error handler at window level
alert("Oops : there seems to be something wrong in your archive. Please report it to us by email or through Github (see About section), with the names of the archive and article and the following info : " alert("Oops : there seems to be something wrong in your archive. Please report it to us by email or through Github (see About section), with the names of the archive and article and the following info : "
+ "Unable to find redirected article for title " + title.name + " : offset " + title.blockStart + " not found in title file"); + "Unable to find redirected article for title " + title._name + " : offset " + title._blockStart + " not found in title file");
throw new Error("Unable to find redirected article for title " + title.name + " : offset " + title.blockStart + " not found in title file"); throw new Error("Unable to find redirected article for title " + title._name + " : offset " + title._blockStart + " not found in title file");
} }
var redirectedTitle = title; var redirectedTitle = title;
redirectedTitle.fileNr = 1 * byteArray[2]; redirectedTitle._fileNr = 1 * byteArray[2];
redirectedTitle.blockStart = util.readIntegerFrom4Bytes(byteArray, 3); redirectedTitle._blockStart = util.readIntegerFrom4Bytes(byteArray, 3);
redirectedTitle.blockOffset = util.readIntegerFrom4Bytes(byteArray, 7); redirectedTitle._blockOffset = util.readIntegerFrom4Bytes(byteArray, 7);
redirectedTitle.articleLength = util.readIntegerFrom4Bytes(byteArray, 11); redirectedTitle._articleLength = util.readIntegerFrom4Bytes(byteArray, 11);
callbackFunction(redirectedTitle); callbackFunction(redirectedTitle);
}; };
// Read only the 16 necessary bytes, starting at title.blockStart // Read only the 16 necessary bytes, starting at title.blockStart
var blob = this.titleFile.slice(title.blockStart, title.blockStart + 16); var blob = this._titleFile.slice(title._blockStart, title._blockStart + 16);
// Read in the file as a binary string // Read in the file as a binary string
reader.readAsArrayBuffer(blob); reader.readAsArrayBuffer(blob);
}; };
@ -656,7 +656,7 @@ define(function(require) {
} }
var normalizedRectangle = rect.normalized(); var normalizedRectangle = rect.normalized();
var titlePositionsFound = new Array(); var titlePositionsFound = new Array();
for (var i = 0; i < this.coordinateFiles.length; i++) { for (var i = 0; i < this._coordinateFiles.length; i++) {
callbackCounterForTitlesInCoordsSearch++; callbackCounterForTitlesInCoordsSearch++;
LocalArchive.getTitlesInCoordsInt(this, i, 0, normalizedRectangle, GLOBE_RECTANGLE, maxTitles, titlePositionsFound, callbackFunction, LocalArchive.callbackGetTitlesInCoordsInt); LocalArchive.getTitlesInCoordsInt(this, i, 0, normalizedRectangle, GLOBE_RECTANGLE, maxTitles, titlePositionsFound, callbackFunction, LocalArchive.callbackGetTitlesInCoordsInt);
} }
@ -857,7 +857,7 @@ define(function(require) {
// TODO : This should be improved by reading the file in 2 steps : // TODO : This should be improved by reading the file in 2 steps :
// - first read the selector // - first read the selector
// - then read the coordinates (reading only the exact necessary bytes) // - then read the coordinates (reading only the exact necessary bytes)
var blob = localArchive.coordinateFiles[coordinateFileIndex].slice(coordFilePos, coordFilePos + 22*65535); var blob = localArchive._coordinateFiles[coordinateFileIndex].slice(coordFilePos, coordFilePos + 22*65535);
// Read in the file as a binary string // Read in the file as a binary string
reader.readAsArrayBuffer(blob); reader.readAsArrayBuffer(blob);
@ -897,7 +897,7 @@ define(function(require) {
* @returns normalized string, or same string if archive is not compatible * @returns normalized string, or same string if archive is not compatible
*/ */
LocalArchive.prototype.normalizeStringIfCompatibleArchive = function(string) { LocalArchive.prototype.normalizeStringIfCompatibleArchive = function(string) {
if (this.normalizedTitles === true) { if (this._normalizedTitles === true) {
return normalize_string.normalizeString(string); return normalize_string.normalizeString(string);
} }
else { else {
@ -910,7 +910,7 @@ define(function(require) {
* If it is not, returns the identity function. * If it is not, returns the identity function.
*/ */
LocalArchive.prototype.getNormalizeFunction = function() { LocalArchive.prototype.getNormalizeFunction = function() {
if (this.normalizedTitles === true) { if (this._normalizedTitles === true) {
return normalize_string.normalizeString; return normalize_string.normalizeString;
} else { } else {
return function(string) { return string; }; return function(string) { return string; };

View File

@ -29,19 +29,18 @@ define(function(require) {
* Title class : defines the title of an article and some methods to manipulate it * Title class : defines the title of an article and some methods to manipulate it
*/ */
function Title() { function Title() {
this.name = null; this._name = null;
this.fileNr = null; this._fileNr = null;
this.blockStart = null; this._blockStart = null;
this.blockOffset = null; this._blockOffset = null;
this.articleLength = null; this._articleLength = null;
this.archive = null; this._archive = null;
this.titleOffset = null; this._titleOffset = null;
this.titleEntryLength = null; this._titleEntryLength = null;
} };
;
Title.prototype.getReadableName = function() { Title.prototype.getReadableName = function() {
return this.name.replace(/_/g, " "); return this._name.replace(/_/g, " ");
}; };
@ -60,16 +59,16 @@ define(function(require) {
throw new Error("Error while parsing an encoded title line un title File : titleOffset cannot be negative (was " + titleOffset + ")"); throw new Error("Error while parsing an encoded title line un title File : titleOffset cannot be negative (was " + titleOffset + ")");
} }
var t = new Title(); var t = new Title();
t.archive = archive; t._archive = archive;
t.titleOffset = titleOffset; t._titleOffset = titleOffset;
if (encodedTitle === null || encodedTitle.length < 15) if (encodedTitle === null || encodedTitle.length < 15)
return null; return null;
if (encodedTitle[encodedTitle.length - 1] == '\n') { if (encodedTitle[encodedTitle.length - 1] == '\n') {
t.titleEntryLength = encodedTitle.length; t._titleEntryLength = encodedTitle.length;
} else { } else {
t.titleEntryLength = encodedTitle.length + 1; t._titleEntryLength = encodedTitle.length + 1;
} }
var escapedEncodedTitle = new Uint8Array(encodedTitle); var escapedEncodedTitle = new Uint8Array(encodedTitle);
@ -81,12 +80,12 @@ define(function(require) {
escapedEncodedTitle[i + 2] = 10; // Corresponds to \n escapedEncodedTitle[i + 2] = 10; // Corresponds to \n
} }
t.fileNr = 1 * escapedEncodedTitle[2]; t._fileNr = 1 * escapedEncodedTitle[2];
t.blockStart = util.readIntegerFrom4Bytes(escapedEncodedTitle, 3); t._blockStart = util.readIntegerFrom4Bytes(escapedEncodedTitle, 3);
t.blockOffset = util.readIntegerFrom4Bytes(escapedEncodedTitle, 7); t._blockOffset = util.readIntegerFrom4Bytes(escapedEncodedTitle, 7);
t.articleLength = util.readIntegerFrom4Bytes(escapedEncodedTitle, 11); t._articleLength = util.readIntegerFrom4Bytes(escapedEncodedTitle, 11);
t.name = Title.parseNameOnly(escapedEncodedTitle); t._name = Title.parseNameOnly(escapedEncodedTitle);
return t; return t;
}; };
@ -114,13 +113,13 @@ define(function(require) {
Title.parseTitleId = function(localArchive, titleId) { Title.parseTitleId = function(localArchive, titleId) {
var title = new Title(); var title = new Title();
var idParts = titleId.split("|"); var idParts = titleId.split("|");
title.archive = localArchive; title._archive = localArchive;
title.fileNr = parseInt(idParts[2], 10); title._fileNr = parseInt(idParts[2], 10);
title.titleOffset = parseInt(idParts[3], 10); title._titleOffset = parseInt(idParts[3], 10);
title.name = idParts[4]; title._name = idParts[4];
title.blockStart = parseInt(idParts[5], 10); title._blockStart = parseInt(idParts[5], 10);
title.blockOffset = parseInt(idParts[6], 10); title._blockOffset = parseInt(idParts[6], 10);
title.articleLength = parseInt(idParts[7], 10); title._articleLength = parseInt(idParts[7], 10);
return title; return title;
}; };
@ -130,15 +129,15 @@ define(function(require) {
* @returns {String} * @returns {String}
*/ */
Title.prototype.toStringId = function() { Title.prototype.toStringId = function() {
return this.archive.language + "|" + this.archive.date + "|" + this.fileNr + "|" return this._archive.language + "|" + this._archive.date + "|" + this._fileNr + "|"
+ this.titleOffset + "|" + this.name + "|" + this.blockStart + "|" + this.blockOffset + "|" + this.articleLength; + this._titleOffset + "|" + this._name + "|" + this._blockStart + "|" + this._blockOffset + "|" + this._articleLength;
}; };
/** /**
* Serialize the title in a readable way * Serialize the title in a readable way
*/ */
Title.prototype.toString = function() { Title.prototype.toString = function() {
return "title.id = " + this.toStringId() + "title.name = " + this.name + " title.fileNr = " + this.fileNr + " title.blockStart = " + this.blockStart + " title.blockOffset = " + this.blockOffset + " title.articleLength = " + this.articleLength; return "title.id = " + this.toStringId() + "title.name = " + this._name + " title.fileNr = " + this._fileNr + " title.blockStart = " + this._blockStart + " title.blockOffset = " + this._blockOffset + " title.articleLength = " + this._articleLength;
}; };
/** /**

View File

@ -34,10 +34,10 @@ define(['utf8', 'title', 'util', 'jquery'], function(utf8, evopediaTitle, util,
* @param offset * @param offset
*/ */
function SequentialTitleIterator(archive, offset) { function SequentialTitleIterator(archive, offset) {
this._titleFile = archive.titleFile; this._titleFile = archive._titleFile;
this._archive = archive; this._archive = archive;
this._offset = offset; this._offset = offset;
this.title = null; this._title = null;
}; };
/** /**
* Advances to the next title (or the first), if possible. * Advances to the next title (or the first), if possible.
@ -46,8 +46,8 @@ define(['utf8', 'title', 'util', 'jquery'], function(utf8, evopediaTitle, util,
*/ */
SequentialTitleIterator.prototype.advance = function() { SequentialTitleIterator.prototype.advance = function() {
if (this._offset >= this._titleFile.size) { if (this._offset >= this._titleFile.size) {
this.title = null; this._title = null;
return jQuery.when(this.title); return jQuery.when(this._title);
} }
var that = this; var that = this;
return util.readFileSlice(this._titleFile, this._offset, return util.readFileSlice(this._titleFile, this._offset,