Ejemplo n.º 1
0
 public void Conflate_TwoWritingSystemsOneIsConflatedIntoOther_OneWritingSystemRemains()
 {
     RepositoryUnderTest.Set(new WritingSystemDefinition("en"));
     RepositoryUnderTest.Set(new WritingSystemDefinition("de"));
     RepositoryUnderTest.Conflate("en", "de");
     Assert.That(RepositoryUnderTest.Contains("de"), Is.True);
     Assert.That(RepositoryUnderTest.Contains("en"), Is.False);
 }
Ejemplo n.º 2
0
        ///<summary>
        /// Constructor.
        ///</summary>
        ///<param name="idsInFile"></param>
        ///<param name="replaceIdsInFile"></param>
        ///<param name="writingSystemRepository"></param>
        public static void FindOrphans(
            IEnumerable <string> idsInFile,
            IdReplacementStrategy replaceIdsInFile,
            IWritingSystemRepository writingSystemRepository)
        {
            List <string> originalIds = idsInFile.ToList();
            List <string> updatedIds  = originalIds.ToList();

            foreach (string wsId in originalIds)
            {
                // Check if it's in the repo
                if (writingSystemRepository.Contains(wsId))
                {
                    continue;
                }
                string newId;
                if (writingSystemRepository.WritingSystemIdHasChanged(wsId))
                {
                    newId = writingSystemRepository.WritingSystemIdHasChangedTo(wsId);
                }
                else
                {
                    // It's an orphan
                    // Clean it
                    var rfcTagCleaner = new IetfLanguageTagCleaner(wsId);
                    rfcTagCleaner.Clean();
                    newId = rfcTagCleaner.GetCompleteTag();
                }

                WritingSystemDefinition conformantWritingSystem;
                writingSystemRepository.WritingSystemFactory.Create(newId, out conformantWritingSystem);
                // If it changed, then change
                if (conformantWritingSystem.LanguageTag != wsId)
                {
                    conformantWritingSystem.LanguageTag = IetfLanguageTag.ToUniqueLanguageTag(
                        conformantWritingSystem.LanguageTag, updatedIds);
                    replaceIdsInFile(wsId, conformantWritingSystem.LanguageTag);
                    updatedIds.Remove(wsId);
                    updatedIds.Add(conformantWritingSystem.LanguageTag);
                }

                // Check if it's in the repo
                if (writingSystemRepository.Contains(conformantWritingSystem.LanguageTag))
                {
                    continue;
                }

                // It's not in the repo so set it
                writingSystemRepository.Set(conformantWritingSystem);
            }
            writingSystemRepository.Save();
        }
 public void SetAllPossibleAndRemoveOthers_HasDuplicateWritingSystems_SetsToRepo()
 {
     Assert.That(_writingSystemRepository.Count, Is.EqualTo(0));
     _model.AddPredefinedDefinition(new WritingSystemDefinition("pt"));
     _model.AddPredefinedDefinition(new WritingSystemDefinition("de"));
     _model.AddPredefinedDefinition(new WritingSystemDefinition("en"));
     _model.AddPredefinedDefinition(new WritingSystemDefinition("en"));
     _model.SetAllPossibleAndRemoveOthers();
     Assert.That(_writingSystemRepository.Count, Is.EqualTo(4));
     Assert.That(_writingSystemRepository.Contains("pt"));
     Assert.That(_writingSystemRepository.Contains("de"));
     Assert.That(_writingSystemRepository.Contains("en"));
     Assert.That(_writingSystemRepository.Contains("en-x-dupl0"));
 }
        ///<summary>
        /// Constructor.
        ///</summary>
        ///<param name="idsInFile"></param>
        ///<param name="replaceIdsInFile"></param>
        ///<param name="writingSystemRepository"></param>
        public static void FindOrphans(
			IEnumerable<string> idsInFile,
			IdReplacementStrategy replaceIdsInFile,
			IWritingSystemRepository writingSystemRepository)
        {
            List<string> originalIds = idsInFile.ToList();
            List<string> updatedIds = originalIds.ToList();
            foreach (string wsId in originalIds)
            {
                // Check if it's in the repo
                if (writingSystemRepository.Contains(wsId))
                {
                    continue;
                }
                string newId;
                if (writingSystemRepository.WritingSystemIdHasChanged(wsId))
                {
                    newId = writingSystemRepository.WritingSystemIdHasChangedTo(wsId);
                }
                else
                {
                    // It's an orphan
                    // Clean it
                    var rfcTagCleaner = new IetfLanguageTagCleaner(wsId);
                    rfcTagCleaner.Clean();
                    newId = rfcTagCleaner.GetCompleteTag();
                }

                WritingSystemDefinition conformantWritingSystem;
                writingSystemRepository.WritingSystemFactory.Create(newId, out conformantWritingSystem);
                // If it changed, then change
                if (conformantWritingSystem.LanguageTag != wsId)
                {
                    conformantWritingSystem.LanguageTag = IetfLanguageTag.ToUniqueLanguageTag(
                        conformantWritingSystem.LanguageTag, updatedIds);
                    replaceIdsInFile(wsId, conformantWritingSystem.LanguageTag);
                    updatedIds.Remove(wsId);
                    updatedIds.Add(conformantWritingSystem.LanguageTag);
                }

                // Check if it's in the repo
                if (writingSystemRepository.Contains(conformantWritingSystem.LanguageTag))
                    continue;

                // It's not in the repo so set it
                writingSystemRepository.Set(conformantWritingSystem);
            }
            writingSystemRepository.Save();
        }
		///<summary>
		/// Constructor.
		///</summary>
		///<param name="idsInFile"></param>
		///<param name="replaceIdsInFile"></param>
		///<param name="writingSystemRepository"></param>
		public static void FindOrphans(
			IEnumerable<string> idsInFile,
			IdReplacementStrategy replaceIdsInFile,
			IWritingSystemRepository writingSystemRepository
		) {
			var originalIds = new List<string>(idsInFile);
			var updatedIds = new List<string>(idsInFile);
			foreach (var wsId in originalIds)
			{
				// Check if it's in the repo
				if (writingSystemRepository.Contains(wsId))
				{
					continue;
				}
				string newId = wsId;
				if (writingSystemRepository.WritingSystemIdHasChanged(wsId))
				{
					newId = writingSystemRepository.WritingSystemIdHasChangedTo(wsId);
				}
				else
				{
					// It's an orphan
					// Check for the writing system repository compatibility mode
					if (writingSystemRepository.CompatibilityMode == WritingSystemCompatibility.Flex7V0Compatible)
					{
						if (!wsId.StartsWith("x-"))
						{
							// Clean it
							var rfcTagCleaner = new Rfc5646TagCleaner(wsId);
							rfcTagCleaner.Clean();
							newId = rfcTagCleaner.GetCompleteTag();
						}
					}
					else
					{
						// Clean it
						var rfcTagCleaner = new Rfc5646TagCleaner(wsId);
						rfcTagCleaner.Clean();
						newId = rfcTagCleaner.GetCompleteTag();
					}
				}
				var conformantWritingSystem = WritingSystemDefinition.Parse(newId);
				// If it changed, then change
				if (conformantWritingSystem.Bcp47Tag != wsId)
				{
					conformantWritingSystem = WritingSystemDefinition.CreateCopyWithUniqueId(conformantWritingSystem, updatedIds);
					replaceIdsInFile(wsId, conformantWritingSystem.Bcp47Tag);
					updatedIds.Remove(wsId);
					updatedIds.Add(conformantWritingSystem.Bcp47Tag);
				}
				// Check if it's in the repo
				if (writingSystemRepository.Contains(conformantWritingSystem.Bcp47Tag))
				{
					continue;
				}
				// It's not in the repo so set it
				writingSystemRepository.Set(conformantWritingSystem);
			}
			writingSystemRepository.Save();
		}
Ejemplo n.º 6
0
        public MultiTextControl(IList <string> writingSystemIds,
                                MultiText multiTextToCopyFormsFrom, string nameForTesting,
                                bool showAnnotationWidget, IWritingSystemRepository allWritingSystems,
                                CommonEnumerations.VisibilitySetting visibility, bool isSpellCheckingEnabled,
                                bool isMultiParagraph, IServiceProvider serviceProvider) : this(allWritingSystems, serviceProvider)
        {
            Name = nameForTesting + "-mtc";
            _writingSystemsForThisField = new List <IWritingSystemDefinition>();
//            foreach (KeyValuePair<string, WritingSystem> pair in allWritingSystems)
//            {
//                if (writingSystemIds.Contains(pair.Key))
//                {
//                    _writingSystemsForThisField.Add(pair.Value);
//                }
//            }
            foreach (var id in writingSystemIds)
            {
                if (allWritingSystems.Contains(id))                 //why wouldn't it?
                {
                    _writingSystemsForThisField.Add(allWritingSystems.Get(id));
                }
            }
            _showAnnotationWidget  = showAnnotationWidget;
            _visibility            = visibility;
            IsSpellCheckingEnabled = isSpellCheckingEnabled;
            _isMultiParagraph      = isMultiParagraph;
            BuildBoxes(multiTextToCopyFormsFrom);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// When the user is playing around with writing system setup, he may delete a
        /// writing system that has been assigned to fields.  In that case, to avoid
        /// crashing (see https://jira.sil.org/browse/WS-233) we need to weed out any
        /// writing systems that no longer exist.
        /// </summary>
        public IList <string> FilterOutBadWritingSystems(IList <string> writingSystemIds)
        {
            List <string> validIds = new List <string>();

            foreach (var id in writingSystemIds)
            {
                if (WritingSystems.Contains(id))
                {
                    validIds.Add(id);
                }
            }
            return(validIds.ToList());
        }
Ejemplo n.º 8
0
 public static void AssertWritingSystemCollectionsAreEqual(IWritingSystemRepository lhs, IWritingSystemRepository rhs)
 {
     foreach (var lhsWritingSystem in lhs.AllWritingSystems)
     {
         var rhsWritingSystem = rhs.Get(lhsWritingSystem.Id);
         Assert.IsTrue(rhs.Contains(lhsWritingSystem.Id));
         Assert.AreEqual(lhsWritingSystem.Id, rhsWritingSystem.Id);
         Assert.AreEqual(lhsWritingSystem.Abbreviation, rhsWritingSystem.Abbreviation);
         Assert.AreEqual(lhsWritingSystem.DefaultFontName, rhsWritingSystem.DefaultFontName);
         Assert.AreEqual(lhsWritingSystem.DefaultFontSize, rhsWritingSystem.DefaultFontSize);
         Assert.AreEqual(lhsWritingSystem.IsVoice, rhsWritingSystem.IsVoice);
         Assert.AreEqual(lhsWritingSystem.IsUnicodeEncoded, rhsWritingSystem.IsUnicodeEncoded);
         Assert.AreEqual(((WritingSystemDefinition)lhsWritingSystem).Keyboard, ((WritingSystemDefinition)rhsWritingSystem).Keyboard);
         Assert.AreEqual(lhsWritingSystem.RightToLeftScript, rhsWritingSystem.RightToLeftScript);
         Assert.AreEqual(lhsWritingSystem.SortUsing, rhsWritingSystem.SortUsing);
         Assert.AreEqual(lhsWritingSystem.SortRules, rhsWritingSystem.SortRules);
         Assert.AreEqual(lhsWritingSystem.SpellCheckingId, rhsWritingSystem.SpellCheckingId);
     }
 }
Ejemplo n.º 9
0
        public void Write_LoadedWritingSystemIsDeleted_DeletionIsRoundTripped()
        {
            using (var e = new TestEnvironment())
            {
                //Write out two writing systems
                IWritingSystemRepository wsCollectionToBeWritten =
                    GetWritingSystemRepository(e.PathToWritingSystemsFolder);
                IWritingSystemDefinition ws = TestEnvironment.CreateDetailedWritingSystem("en");
                wsCollectionToBeWritten.Set(ws);
                IWritingSystemDefinition ws2 = TestEnvironment.CreateDetailedWritingSystem("th");
                wsCollectionToBeWritten.Set(ws2);
                wsCollectionToBeWritten.Save();

                //load them up again
                IWritingSystemRepository loadedWsCollection = GetWritingSystemRepository(e.PathToWritingSystemsFolder);
                loadedWsCollection.Remove(ws.Id);                 //remove one
                loadedWsCollection.Save();

                //Now check that it hasn't come back!
                IWritingSystemRepository loadedWsCollection2 =
                    GetWritingSystemRepository(e.PathToWritingSystemsFolder);
                Assert.IsFalse(loadedWsCollection2.Contains(ws.Id));
            }
        }
Ejemplo n.º 10
0
 /// <summary>
 /// Determines if a writing system exists with the specified RFC5646 identifier.
 /// </summary>
 /// <param name="identifier">The identifier.</param>
 /// <returns></returns>
 public bool Exists(string identifier)
 {
     lock (m_syncRoot)
         return(m_repo.Contains(identifier));
 }
Ejemplo n.º 11
0
        ///<summary>
        /// Constructor.
        ///</summary>
        ///<param name="idsInFile"></param>
        ///<param name="replaceIdsInFile"></param>
        ///<param name="writingSystemRepository"></param>
        public static void FindOrphans(
            IEnumerable <string> idsInFile,
            IdReplacementStrategy replaceIdsInFile,
            IWritingSystemRepository writingSystemRepository
            )
        {
            var originalIds = new List <string>(idsInFile);
            var updatedIds  = new List <string>(idsInFile);

            foreach (var wsId in originalIds)
            {
                // Check if it's in the repo
                if (writingSystemRepository.Contains(wsId))
                {
                    continue;
                }
                string newId = wsId;
                if (writingSystemRepository.WritingSystemIdHasChanged(wsId))
                {
                    newId = writingSystemRepository.WritingSystemIdHasChangedTo(wsId);
                }
                else
                {
                    // It's an orphan
                    // Check for the writing system repository compatibility mode
                    if (writingSystemRepository.CompatibilityMode == WritingSystemCompatibility.Flex7V0Compatible)
                    {
                        if (!wsId.StartsWith("x-"))
                        {
                            // Clean it
                            var rfcTagCleaner = new Rfc5646TagCleaner(wsId);
                            rfcTagCleaner.Clean();
                            newId = rfcTagCleaner.GetCompleteTag();
                        }
                    }
                    else
                    {
                        // Clean it
                        var rfcTagCleaner = new Rfc5646TagCleaner(wsId);
                        rfcTagCleaner.Clean();
                        newId = rfcTagCleaner.GetCompleteTag();
                    }
                }
                var conformantWritingSystem = WritingSystemDefinition.Parse(newId);
                // If it changed, then change
                if (conformantWritingSystem.Bcp47Tag != wsId)
                {
                    conformantWritingSystem = WritingSystemDefinition.CreateCopyWithUniqueId(conformantWritingSystem, updatedIds);
                    replaceIdsInFile(wsId, conformantWritingSystem.Bcp47Tag);
                    updatedIds.Remove(wsId);
                    updatedIds.Add(conformantWritingSystem.Bcp47Tag);
                }
                // Check if it's in the repo
                if (writingSystemRepository.Contains(conformantWritingSystem.Bcp47Tag))
                {
                    continue;
                }
                // It's not in the repo so set it
                writingSystemRepository.Set(conformantWritingSystem);
            }
            writingSystemRepository.Save();
        }
Ejemplo n.º 12
0
        internal void SetWritingSystemsForFields()
        {
            var liftDom = new XmlDocument();

            liftDom.Load(_path);             //will throw if the file is ill-formed
            var missingWritingSystems = new StringBuilder();

            foreach (XmlNode node in liftDom.SelectNodes("//@lang"))
            {
                if (node.Value == "x-spec" && !_writingSystems.Contains("x-spec"))
                {
                    _writingSystems.Set(WritingSystemDefinition.Parse("x-spec"));
                }
                if (!_writingSystems.Contains(node.Value))
                {
                    _writingSystems.Set(WritingSystemDefinition.Parse(node.Value));
                    missingWritingSystems.AppendFormat("{0},", node.Value);
                }
            }
            _writingSystems.Save();

            if (missingWritingSystems.Length > 0)
            {
                var list = missingWritingSystems.ToString().Trim(new[] { ',' });
                ErrorReport.NotifyUserOfProblem(
                    "WeSay had a problem locating information on at least one input system used in the LIFT export from FLEx.  One known cause of this is an old version of FLEx. In the folder containing the LIFT file, there should have been '___.ldml' files for the following input systems: {0}.\r\nBecause these input system definitions were not found, WeSay will create blank input systems for each of these, which you will need to set up with the right fonts, keyboards, etc.", list);
            }
            // replace all "v" fields with the first lexical-unit writing system
            //and all "en" with the first translation one...

            var vernacular = GetTopWritingSystem(liftDom, "//lexical-unit/form/@lang");

            if (vernacular != String.Empty)
            {
                _viewTemplate.OnWritingSystemIDChange(WeSayWordsProject.VernacularWritingSystemIdForProjectCreation, vernacular);
                if (_writingSystems.Contains(WeSayWordsProject.VernacularWritingSystemIdForProjectCreation))
                {
                    _writingSystems.Remove(WeSayWordsProject.VernacularWritingSystemIdForProjectCreation);
                }
            }
            var analysis = GetTopWritingSystem(liftDom, "//sense/gloss/@lang");

            if (analysis == String.Empty)
            {
                analysis = GetTopWritingSystem(liftDom, "//sense/definition/@lang");
                //nb: we don't want to remove english, even if they don't use it
            }
            if (analysis != String.Empty)
            {
                _viewTemplate.OnWritingSystemIDChange(WeSayWordsProject.AnalysisWritingSystemIdForProjectCreation, analysis);
            }

            AddWritingSystemsForField(liftDom, "//lexical-unit/form/@lang", LexEntry.WellKnownProperties.LexicalUnit);
            AddWritingSystemsForField(liftDom, "//sense/gloss/@lang", LexSense.WellKnownProperties.Gloss);

            AddWritingSystemsForField(liftDom, "//sense/definition/form/@lang", LexSense.WellKnownProperties.Definition);

            AddAllGlossWritingSystemsToDefinition();

            AddWritingSystemsForField(liftDom, "//example/form/@lang", LexExampleSentence.WellKnownProperties.ExampleSentence);
            AddWritingSystemsForField(liftDom, "//translation/form/@lang", LexExampleSentence.WellKnownProperties.Translation);

            //------------ hack
            var gloss = _viewTemplate.GetField(LexSense.WellKnownProperties.Gloss);
            var def   = _viewTemplate.GetField(LexSense.WellKnownProperties.Definition);

            foreach (var id in def.WritingSystemIds)
            {
                if (!gloss.WritingSystemIds.Contains(id))
                {
                    gloss.WritingSystemIds.Add(id);
                }
            }
            foreach (var id in gloss.WritingSystemIds)
            {
                if (!def.WritingSystemIds.Contains(id))
                {
                    def.WritingSystemIds.Add(id);
                }
            }
        }