/* (C) 2022 Cadence Design Systems, Inc. (Cadence) All rights reserved. TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is provided to current licensees or subscribers of Cadence products or SaaS offerings (each a "Customer"). Customer is hereby permitted to use, copy, and modify the Sample Code, subject to these terms. Cadence claims no rights to Customer's modifications. Modification of Sample Code is at Customer's sole and exclusive risk. Sample Code may require Customer to have a then current license or subscription to the applicable Cadence offering. THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED. OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be liable for any damages or liability in connection with the Sample Code or its use. */ /***************************************************************************** Translates between languages. Internally LexichemTK uses American English so it will convert to/from that as an intermediate representation. By default the program inputs/outputs the internal LexichemTK character set representation. Optionally one can convert the input or output to alternate encodings, eg: HTML or UTF8. *****************************************************************************/ using System; using OpenEye.OEChem; using OpenEye.OEIUPAC; public class Translate_example { private void Translate(OEInterface itf) { System.IO.StreamReader ifs = new System.IO.StreamReader(itf.GetString("-in")); System.IO.StreamWriter sw = null; if (itf.HasString("-o")) { try { sw = new System.IO.StreamWriter(itf.GetString("-o")); Console.SetOut(sw); } catch { OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-o") + " for writing"); } } uint to_language = OEIUPAC.OEGetIUPACLanguage(itf.GetString("-to_language")); uint from_language = OEIUPAC.OEGetIUPACLanguage(itf.GetString("-from_language")); uint from_charset = OEIUPAC.OEGetIUPACCharSet(itf.GetString("-from_charset")); uint to_charset = OEIUPAC.OEGetIUPACCharSet(itf.GetString("-to_charset")); string name = ""; while ((name = ifs.ReadLine()) != null) { // Convert from charset to internal representation if (from_charset == OECharSet.UTF8) name = OEIUPAC.OEFromUTF8(name); else if (from_charset == OECharSet.HTML) name = OEIUPAC.OEFromHTML(name); // Translation functions operate on lowercase names name = OEIUPAC.OELowerCaseName(name); if (from_language != OELanguage.AMERICAN) name = OEIUPAC.OEFromLanguage(name, from_language); // At this point the name is American English in the // LexichemTK default internal character set representation. // Convert to output language if (to_language != OELanguage.AMERICAN) name = OEIUPAC.OEToLanguage(name, to_language); // Convert to output charset if (to_charset == OECharSet.ASCII) name = OEIUPAC.OEToASCII(name); else if (to_charset == OECharSet.UTF8) name = OEIUPAC.OEToUTF8(name); else if (to_charset == OECharSet.HTML) name = OEIUPAC.OEToHTML(name); else if (to_charset == OECharSet.SJIS) name = OEIUPAC.OEToSJIS(name); else if (to_charset == OECharSet.EUCJP) name = OEIUPAC.OEToEUCJP(name); Console.WriteLine(name); } if (itf.HasString("-o")) sw.Close(); } public static void Main(string[] argv) { Translate_example app = new Translate_example(); OEInterface itf = new OEInterface(interfaceData, "Translate_example", argv); app.Translate(itf); } private static string interfaceData = @" # translate interface file !CATEGORY translate !PARAMETER -in 1 !ALIAS -i !TYPE string !REQUIRED true !BRIEF Input filename !KEYLESS 1 !END !PARAMETER -out 2 !ALIAS -o !TYPE string !BRIEF Output filename !KEYLESS 2 !END !PARAMETER -from 3 !ALIAS -from_language !TYPE string !DEFAULT american !LEGAL_VALUE american !LEGAL_VALUE english !LEGAL_VALUE us !LEGAL_VALUE chinese !LEGAL_VALUE zh !LEGAL_VALUE cn !LEGAL_VALUE danish !LEGAL_VALUE dk !LEGAL_VALUE da !LEGAL_VALUE dutch !LEGAL_VALUE nl !LEGAL_VALUE french !LEGAL_VALUE fr !LEGAL_VALUE german !LEGAL_VALUE de !LEGAL_VALUE greek !LEGAL_VALUE el !LEGAL_VALUE hungarian !LEGAL_VALUE hu !LEGAL_VALUE irish !LEGAL_VALUE ie !LEGAL_VALUE ga !LEGAL_VALUE italian !LEGAL_VALUE it !LEGAL_VALUE japanese !LEGAL_VALUE jp !LEGAL_VALUE ja !LEGAL_VALUE polish !LEGAL_VALUE pl !LEGAL_VALUE portuguese !LEGAL_VALUE pt !LEGAL_VALUE romanian !LEGAL_VALUE ro !LEGAL_VALUE russian !LEGAL_VALUE ru !LEGAL_VALUE slovak !LEGAL_VALUE sk !LEGAL_VALUE spanish !LEGAL_VALUE es !LEGAL_VALUE swedish !LEGAL_VALUE se !LEGAL_VALUE sv !LEGAL_VALUE welsh !LEGAL_VALUE cy !REQUIRED false !BRIEF Language for input names. !END !PARAMETER -to 4 !ALIAS -to_language !TYPE string !DEFAULT american !LEGAL_VALUE american !LEGAL_VALUE english !LEGAL_VALUE us !LEGAL_VALUE chinese !LEGAL_VALUE zh !LEGAL_VALUE cn !LEGAL_VALUE danish !LEGAL_VALUE dk !LEGAL_VALUE da !LEGAL_VALUE dutch !LEGAL_VALUE nl !LEGAL_VALUE french !LEGAL_VALUE fr !LEGAL_VALUE german !LEGAL_VALUE de !LEGAL_VALUE greek !LEGAL_VALUE el !LEGAL_VALUE hungarian !LEGAL_VALUE hu !LEGAL_VALUE irish !LEGAL_VALUE ie !LEGAL_VALUE ga !LEGAL_VALUE italian !LEGAL_VALUE it !LEGAL_VALUE japanese !LEGAL_VALUE jp !LEGAL_VALUE ja !LEGAL_VALUE polish !LEGAL_VALUE pl !LEGAL_VALUE portuguese !LEGAL_VALUE pt !LEGAL_VALUE romanian !LEGAL_VALUE ro !LEGAL_VALUE russian !LEGAL_VALUE ru !LEGAL_VALUE slovak !LEGAL_VALUE sk !LEGAL_VALUE spanish !LEGAL_VALUE es !LEGAL_VALUE swedish !LEGAL_VALUE se !LEGAL_VALUE sv !LEGAL_VALUE welsh !LEGAL_VALUE cy !REQUIRED false !BRIEF Language for input names. !END !PARAMETER -from_charset 5 !TYPE string !DEFAULT default !REQUIRED false !LEGAL_VALUE default !LEGAL_VALUE ascii !LEGAL_VALUE utf8 !LEGAL_VALUE html !LEGAL_VALUE sjis !LEGAL_VALUE eucjp !BRIEF Choose charset/encoding for input names. !END !PARAMETER -to_charset 6 !ALIAS -encoding !ALIAS -charset !TYPE string !DEFAULT default !REQUIRED false !LEGAL_VALUE default !LEGAL_VALUE ascii !LEGAL_VALUE utf8 !LEGAL_VALUE html !LEGAL_VALUE sjis !LEGAL_VALUE eucjp !BRIEF Choose charset/encoding for output names. !END !PARAMETER -debug !TYPE bool !DEFAULT false !VISIBILITY hidden !END !END "; }