<commit_before>// Amara, universalsubtitles.org
//
// Copyright (C) 2012 Participatory Culture Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see
// http://www.gnu.org/licenses/agpl-3.0.html.

/*
 * We store a local cache of language data + subtitles in the following format:
 * [
 *   {
 *      "code": "en",
 *      "editingLanguage": true,
 *      "versions": [
 *        {
 *          "title": "About Amara",
 *          "number": 4,
 *          "subtitlesXML": "<dfxp subs>",
 *          "description": "<some description>"
 *        }
 *      ],
 *      "numVersions": 1,
 *      "translatedFrom": {
 *        "version_number": 3,
 *        "language_code": "en"
 *      },
 *      "pk": 1,
 *      "name": "English"
 *   }
 * ]
 *
 * When you request a set of subtitles the api is hit if data is not yet on
 * the cache.
 */

(function() {

    var root, module;

    root = this;
    module = angular.module('amara.SubtitleEditor.services', []);

    module.factory("SubtitleFetcher", function($http) {
        var cachedData = window.editorData ;
        return {

            getSubtitles: function(languageCode, versionNumber, callback){
                var subtitlesXML = undefined;
                // will trigger a subtitlesFetched event when ready
                for (var i=0; i < cachedData.languages.length ; i++){
                    var langObj = cachedData.languages[i];
                    if (langObj.code == languageCode){
                        for (var j = 1; j < langObj.versions.length + 1; j++){
                            if (langObj.versions[j].number == versionNumber){
                                subtitlesXML = langObj.versions[j].subtitlesXML;
                                break;
                            }
                        }
                        break;
                    }
                }
                if (subtitlesXML !== undefined){
                   callback(subtitlesXML);
                }else{
                    // fetch data
                }
                return;
            }
        };
    });

}).call(this);
<commit_msg>Some documentation on the subtitles service<commit_after>// Amara, universalsubtitles.org
//
// Copyright (C) 2012 Participatory Culture Foundation
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see
// http://www.gnu.org/licenses/agpl-3.0.html.

/*
 * We store a local cache of language data + subtitles in the following format:
 * [
 *   {
 *      "code": "en",
 *      "editingLanguage": true,
 *      "versions": [
 *        {
 *          "title": "About Amara",
 *          "number": 4,
 *          "subtitlesXML": "<dfxp subs>",
 *          "description": "<some description>"
 *        }
 *      ],
 *      "numVersions": 1,
 *      "translatedFrom": {
 *        "version_number": 3,
 *        "language_code": "en"
 *      },
 *      "pk": 1,
 *      "name": "English"
 *   }
 * ]
 *
 * When you request a set of subtitles the api is hit if data is not yet on
 * the cache.
 */

(function() {

    var root, module;

    root = this;
    module = angular.module('amara.SubtitleEditor.services', []);

    module.factory("SubtitleFetcher", function($http) {
        var cachedData = window.editorData ;
        return {

            /**
             * Tries to find the data in an in memory, if it's not there
             * fetch from the server side.
             * @param languageCode
             * @param versionNumber
             * @param callback Function to be called with the dfxp xlm
             * once it's ready.
             */
            getSubtitles: function(languageCode, versionNumber, callback){
                var subtitlesXML = undefined;
                // will trigger a subtitlesFetched event when ready
                for (var i=0; i < cachedData.languages.length ; i++){
                    var langObj = cachedData.languages[i];
                    if (langObj.code == languageCode){
                        for (var j = 1; j < langObj.versions.length + 1; j++){
                            if (langObj.versions[j].number == versionNumber){
                                subtitlesXML = langObj.versions[j].subtitlesXML;
                                break;
                            }
                        }
                        break;
                    }
                }
                if (subtitlesXML !== undefined){
                   callback(subtitlesXML);
                }else{
                    // fetch data
                }
                return;
            }
        };
    });

}).call(this);

{'fraction_non_alphanumeric': 0.10653458463677441, 'fraction_numerical': 0.004866180048661801, 'mean_word_length': 1.6087941976427924, 'pattern_counts': {'":': 26, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4886225', 'n_tokens_mistral': 1549, 'n_tokens_neox': 1479, 'n_words': 508}