/* * prime = prime20; * Main(32); * NetSimulator.Reset(); * * prime = prime30; * Main(32); * NetSimulator.Reset(); * * prime = prime40; * Main(32); * NetSimulator.Reset(); * * prime = prime50; * Main(32); * NetSimulator.Reset(); */ public static void Main(int n) // number of parties { Debug.Assert(NumTheoryUtils.MillerRabin(prime, 5) == false); // must be a prime // Create an MPC network, add parties, and init them with random inputs NetSimulator.Init(seed); //seed StaticRandom.Init(seed + 1); //seed + 1 Quorum q = new Quorum(0, 0, n); SetupMps(n); //SetupMultiQuorumCircuitEvaluation(q); Console.WriteLine(n + " parties initialized. Running simulation...\n"); // run the simulator var elapsedTime = Timex.Run(() => NetSimulator.Run()); // CheckMps(n); //ReconstructDictionary(q, network.LastGateForWire, 4); Console.WriteLine("Simulation finished. Checking results...\n"); Console.WriteLine("# parties = " + n); Console.WriteLine("# msgs sent = " + NetSimulator.SentMessageCount.ToString("0.##E+00")); Console.WriteLine("# bits sent = " + (NetSimulator.SentByteCount * 8).ToString("0.##E+00")); Console.WriteLine("Rounds = " + NetSimulator.RoundCount + "\n"); Console.WriteLine("Key size = " + NumTheoryUtils.GetBitLength2(prime) + " bits"); Console.WriteLine("Seed = " + seed + "\n"); Console.WriteLine("Elapsed time = " + elapsedTime.ToString("hh':'mm':'ss'.'fff") + "\n"); }
private static void WriteTime(JSONOutputter.IWriter l3, Timex time) { if (time != null) { Timex.Range range = time.Range(); l3.Set("timex", (IConsumer <JSONOutputter.IWriter>)null); } }
private static void DisplayAnnotation(PrintWriter @out, string query, Annotation anno, bool includeOffsets) { IList <ICoreMap> timexAnns = anno.Get(typeof(TimeAnnotations.TimexAnnotations)); IList <string> pieces = new List <string>(); IList <bool> tagged = new List <bool>(); int previousEnd = 0; foreach (ICoreMap timexAnn in timexAnns) { int begin = timexAnn.Get(typeof(CoreAnnotations.CharacterOffsetBeginAnnotation)); int end = timexAnn.Get(typeof(CoreAnnotations.CharacterOffsetEndAnnotation)); if (begin >= previousEnd) { pieces.Add(Sharpen.Runtime.Substring(query, previousEnd, begin)); tagged.Add(false); pieces.Add(Sharpen.Runtime.Substring(query, begin, end)); tagged.Add(true); previousEnd = end; } } if (previousEnd < query.Length) { pieces.Add(Sharpen.Runtime.Substring(query, previousEnd)); tagged.Add(false); } @out.Println("<table id='Annotated'><tr><td>"); for (int i = 0; i < pieces.Count; ++i) { if (tagged[i]) { @out.Print("<span style=\"background-color: #FF8888\">"); @out.Print(StringEscapeUtils.EscapeHtml4(pieces[i])); @out.Print("</span>"); } else { @out.Print(StringEscapeUtils.EscapeHtml4(pieces[i])); } } @out.Println("</td></tr></table>"); @out.Println("<h3>Temporal Expressions</h3>"); if (timexAnns.Count > 0) { @out.Println("<table>"); @out.Println("<tr><th>Text</th><th>Value</th>"); if (includeOffsets) { @out.Println("<th>Char Begin</th><th>Char End</th><th>Token Begin</th><th>Token End</th>"); } @out.Println("<th>Timex3 Tag</th></tr>"); foreach (ICoreMap timexAnn_1 in timexAnns) { @out.Println("<tr>"); Timex timex = timexAnn_1.Get(typeof(TimeAnnotations.TimexAnnotation)); int begin = timexAnn_1.Get(typeof(CoreAnnotations.CharacterOffsetBeginAnnotation)); int end = timexAnn_1.Get(typeof(CoreAnnotations.CharacterOffsetEndAnnotation)); @out.Print("<td>" + StringEscapeUtils.EscapeHtml4(Sharpen.Runtime.Substring(query, begin, end)) + "</td>"); @out.Print("<td>" + ((timex.Value() != null) ? StringEscapeUtils.EscapeHtml4(timex.Value()) : string.Empty) + "</td>"); if (includeOffsets) { @out.Print("<td>" + begin + "</td>"); @out.Print("<td>" + end + "</td>"); @out.Print("<td>" + timexAnn_1.Get(typeof(CoreAnnotations.TokenBeginAnnotation)) + "</td>"); @out.Print("<td>" + timexAnn_1.Get(typeof(CoreAnnotations.TokenEndAnnotation)) + "</td>"); } @out.Print("<td>" + StringEscapeUtils.EscapeHtml4(timex.ToString()) + "</td>"); @out.Println("</tr>"); } @out.Println("</table>"); } else { @out.Println("<em>No temporal expressions.</em>"); } @out.Println("<h3>POS Tags</h3>"); @out.Println("<table><tr><td>"); foreach (ICoreMap sentence in anno.Get(typeof(CoreAnnotations.SentencesAnnotation))) { IList <CoreLabel> tokens = sentence.Get(typeof(CoreAnnotations.TokensAnnotation)); foreach (CoreLabel token in tokens) { string tokenOutput = StringEscapeUtils.EscapeHtml4(token.Word() + "/" + token.Tag()); @out.Print(tokenOutput + " "); } @out.Println("<br>"); } @out.Println("</td></tr></table>"); }
public virtual void Annotate(Annotation annotation) { IList <ICoreMap> sentences = annotation.Get(typeof(CoreAnnotations.SentencesAnnotation)); int sentenceIndex = 0; foreach (ICoreMap sentence in sentences) { IList <CoreLabel> tokens = sentence.Get(typeof(CoreAnnotations.TokensAnnotation)); int annoTokenBegin = sentence.Get(typeof(CoreAnnotations.TokenBeginAnnotation)); if (annoTokenBegin == null) { annoTokenBegin = 0; } IList <ICoreMap> chunks = chunkIdentifier.GetAnnotatedChunks(tokens, annoTokenBegin, typeof(CoreAnnotations.TextAnnotation), nerCoreAnnotationClass, IsTokensCompatible); sentence.Set(mentionsCoreAnnotationClass, chunks); // By now entity mentions have been annotated and TextAnnotation and NamedEntityAnnotation marked // Some additional annotations IList <ICoreMap> mentions = sentence.Get(mentionsCoreAnnotationClass); if (mentions != null) { foreach (ICoreMap mention in mentions) { IList <CoreLabel> mentionTokens = mention.Get(typeof(CoreAnnotations.TokensAnnotation)); string name = (string)CoreMapAttributeAggregator.FirstNonNil.Aggregate(nerNormalizedCoreAnnotationClass, mentionTokens); if (name == null) { name = mention.Get(typeof(CoreAnnotations.TextAnnotation)); } else { mention.Set(nerNormalizedCoreAnnotationClass, name); } //mention.set(CoreAnnotations.EntityNameAnnotation.class, name); string type = mention.Get(nerCoreAnnotationClass); mention.Set(typeof(CoreAnnotations.EntityTypeAnnotation), type); // set sentence index annotation for mention mention.Set(typeof(CoreAnnotations.SentenceIndexAnnotation), sentenceIndex); // Take first non nil as timex for the mention Timex timex = (Timex)CoreMapAttributeAggregator.FirstNonNil.Aggregate(typeof(TimeAnnotations.TimexAnnotation), mentionTokens); if (timex != null) { mention.Set(typeof(TimeAnnotations.TimexAnnotation), timex); } // Set the entity link from the tokens if (mention.Get(typeof(CoreAnnotations.WikipediaEntityAnnotation)) == null) { foreach (CoreLabel token in mentionTokens) { if ((mention.Get(typeof(CoreAnnotations.WikipediaEntityAnnotation)) == null || "O".Equals(mention.Get(typeof(CoreAnnotations.WikipediaEntityAnnotation)))) && (token.Get(typeof(CoreAnnotations.WikipediaEntityAnnotation)) != null && !"O".Equals (token.Get(typeof(CoreAnnotations.WikipediaEntityAnnotation))))) { mention.Set(typeof(CoreAnnotations.WikipediaEntityAnnotation), token.Get(typeof(CoreAnnotations.WikipediaEntityAnnotation))); } } } } } sentenceIndex++; } // Post-process with acronyms if (doAcronyms) { AddAcronyms(annotation); } // Post-process add in KBP pronominal mentions, (English only for now) if (entityMentionsLanguage.Equals(LanguageInfo.HumanLanguage.English)) { AnnotatePronominalMentions(annotation); } // build document wide entity mentions list IList <ICoreMap> allEntityMentions = new List <ICoreMap>(); int entityMentionIndex = 0; foreach (ICoreMap sentence_1 in annotation.Get(typeof(CoreAnnotations.SentencesAnnotation))) { foreach (ICoreMap entityMention in sentence_1.Get(typeof(CoreAnnotations.MentionsAnnotation))) { entityMention.Set(typeof(CoreAnnotations.EntityMentionIndexAnnotation), entityMentionIndex); entityMention.Set(typeof(CoreAnnotations.CanonicalEntityMentionIndexAnnotation), entityMentionIndex); foreach (CoreLabel entityMentionToken in entityMention.Get(typeof(CoreAnnotations.TokensAnnotation))) { entityMentionToken.Set(typeof(CoreAnnotations.EntityMentionIndexAnnotation), entityMentionIndex); } allEntityMentions.Add(entityMention); entityMentionIndex++; } } annotation.Set(mentionsCoreAnnotationClass, allEntityMentions); }
private static void AddWordInfo(Element wordInfo, ICoreMap token, int id, string curNS) { // store the position of this word in the sentence wordInfo.AddAttribute(new Attribute("id", int.ToString(id))); SetSingleElement(wordInfo, "word", curNS, token.Get(typeof(CoreAnnotations.TextAnnotation))); SetSingleElement(wordInfo, "lemma", curNS, token.Get(typeof(CoreAnnotations.LemmaAnnotation))); if (token.ContainsKey(typeof(CoreAnnotations.CharacterOffsetBeginAnnotation)) && token.ContainsKey(typeof(CoreAnnotations.CharacterOffsetEndAnnotation))) { SetSingleElement(wordInfo, "CharacterOffsetBegin", curNS, int.ToString(token.Get(typeof(CoreAnnotations.CharacterOffsetBeginAnnotation)))); SetSingleElement(wordInfo, "CharacterOffsetEnd", curNS, int.ToString(token.Get(typeof(CoreAnnotations.CharacterOffsetEndAnnotation)))); } if (token.ContainsKey(typeof(CoreAnnotations.PartOfSpeechAnnotation))) { SetSingleElement(wordInfo, "POS", curNS, token.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation))); } if (token.ContainsKey(typeof(CoreAnnotations.NamedEntityTagAnnotation))) { SetSingleElement(wordInfo, "NER", curNS, token.Get(typeof(CoreAnnotations.NamedEntityTagAnnotation))); } if (token.ContainsKey(typeof(CoreAnnotations.NormalizedNamedEntityTagAnnotation))) { SetSingleElement(wordInfo, "NormalizedNER", curNS, token.Get(typeof(CoreAnnotations.NormalizedNamedEntityTagAnnotation))); } if (token.ContainsKey(typeof(CoreAnnotations.SpeakerAnnotation))) { SetSingleElement(wordInfo, "Speaker", curNS, token.Get(typeof(CoreAnnotations.SpeakerAnnotation))); } if (token.ContainsKey(typeof(TimeAnnotations.TimexAnnotation))) { Timex timex = token.Get(typeof(TimeAnnotations.TimexAnnotation)); Element timexElem = new Element("Timex", curNS); timexElem.AddAttribute(new Attribute("tid", timex.Tid())); timexElem.AddAttribute(new Attribute("type", timex.TimexType())); timexElem.AppendChild(timex.Value()); wordInfo.AppendChild(timexElem); } if (token.ContainsKey(typeof(CoreAnnotations.TrueCaseAnnotation))) { Element cur = new Element("TrueCase", curNS); cur.AppendChild(token.Get(typeof(CoreAnnotations.TrueCaseAnnotation))); wordInfo.AppendChild(cur); } if (token.ContainsKey(typeof(CoreAnnotations.TrueCaseTextAnnotation))) { Element cur = new Element("TrueCaseText", curNS); cur.AppendChild(token.Get(typeof(CoreAnnotations.TrueCaseTextAnnotation))); wordInfo.AppendChild(cur); } if (token.ContainsKey(typeof(SentimentCoreAnnotations.SentimentClass))) { Element cur = new Element("sentiment", curNS); cur.AppendChild(token.Get(typeof(SentimentCoreAnnotations.SentimentClass))); wordInfo.AppendChild(cur); } if (token.ContainsKey(typeof(CoreAnnotations.WikipediaEntityAnnotation))) { Element cur = new Element("entitylink", curNS); cur.AppendChild(token.Get(typeof(CoreAnnotations.WikipediaEntityAnnotation))); wordInfo.AppendChild(cur); } }
/// <summary>Link the given mention, if possible.</summary> /// <param name="mention"> /// The mention to link, as given by /// <see cref="EntityMentionsAnnotator"/> /// </param> /// <returns>The Wikidict entry for the given mention, or the normalized timex / numeric value -- as appropriate.</returns> public virtual Optional <string> Link(ICoreMap mention) { string surfaceForm = mention.Get(typeof(CoreAnnotations.OriginalTextAnnotation)) == null?mention.Get(typeof(CoreAnnotations.TextAnnotation)) : mention.Get(typeof(CoreAnnotations.OriginalTextAnnotation)); // set up key for wikidict ; if caseless use lower case version of surface form string mentionSurfaceFormKey; if (wikidictCaseless) { mentionSurfaceFormKey = surfaceForm.ToLower(); } else { mentionSurfaceFormKey = surfaceForm; } // get ner string ner = mention.Get(typeof(CoreAnnotations.NamedEntityTagAnnotation)); if (ner != null && (Sharpen.Runtime.EqualsIgnoreCase(KBPRelationExtractor.NERTag.Date.name, ner) || Sharpen.Runtime.EqualsIgnoreCase("TIME", ner) || Sharpen.Runtime.EqualsIgnoreCase("SET", ner)) && mention.Get(typeof(TimeAnnotations.TimexAnnotation )) != null && mention.Get(typeof(TimeAnnotations.TimexAnnotation)).Value() != null) { // Case: normalize dates Timex timex = mention.Get(typeof(TimeAnnotations.TimexAnnotation)); if (timex.Value() != null && !timex.Value().Equals("PRESENT") && !timex.Value().Equals("PRESENT_REF") && !timex.Value().Equals("PAST") && !timex.Value().Equals("PAST_REF") && !timex.Value().Equals("FUTURE") && !timex.Value().Equals("FUTURE_REF" )) { return(Optional.Of(NormalizeTimex(timex.Value()))); } else { return(Optional.Empty()); } } else { if (ner != null && Sharpen.Runtime.EqualsIgnoreCase("ORDINAL", ner) && mention.Get(typeof(CoreAnnotations.NumericValueAnnotation)) != null) { // Case: normalize ordinals Number numericValue = mention.Get(typeof(CoreAnnotations.NumericValueAnnotation)); return(Optional.Of(numericValue.ToString())); } else { if (NumberPattern.Matcher(surfaceForm).Matches()) { // Case: keep numbers as is return(Optional.Of(surfaceForm)); } else { if (ner != null && !"O".Equals(ner) && dictionary.Contains(mentionSurfaceFormKey)) { // Case: link with Wikidict return(Optional.Of(dictionary[mentionSurfaceFormKey])); } else { // Else: keep the surface form as is return(Optional.Empty()); } } } } }
public static void GetLatest() { if (!Directory.Exists(@"C:\JizHydrusLatest\")) { Directory.CreateDirectory(@"C:\JizHydrusLatest\"); } using (var context = new JizanOMSContext()) { try { List <tblGateway> gateway = new List <tblGateway>(); var y = from j in context.tblGateways select j; gateway = y.ToList(); //delete all latest here var result = context.Database.ExecuteSqlCommand("delete from tblLatest"); Console.WriteLine($"Delete {result} from Latest Table"); foreach (var g in gateway) { var x = context.GetLatestMeterReading(g.Name); //Console.WriteLine(x); var extractMeter = context.Database .SqlQuery <CustomLatest>( "SELECT DISTINCT MeterAddress, ReadingDate, RawTelegram FROM tblLatest WHERE GatewayId=@GatewayId", new SqlParameter("@GatewayId", g.Name)); var fileName = Timex.CurrentTime(); string path2 = @"C:\JizHydrusLatest\" + g.Name + "\\" + fileName + ".csv"; if (!Directory.Exists(@"C:\JizHydrusLatest\" + g.Name + "\\")) { Directory.CreateDirectory(@"C:\JizHydrusLatest\" + g.Name + "\\"); } using (StreamWriter writer = new StreamWriter(path2, false)) { string[] separator = { "," }; var filecontents = new StringBuilder(); filecontents.Append("METER_ADDRESS, READING_DATE, PACKET\r\n"); string extract = null; foreach (var em in extractMeter) { extract += em.MeterAddress + ","; //Serial extract += em.ReadingDate .ToString() .DBtoCSVDateConvert() + ","; //Date extract += em.RawTelegram; //Packet extract += "\r\n"; } filecontents.Append(extract); writer.Write(filecontents.ToString()); writer.Flush(); writer.Close(); } } //MessageBox.Show("Latest record/s extracted."); Console.WriteLine("Latest record/s extracted."); //Console.WriteLine("Extracted"); } catch (Exception) { return; } } }
public static void ExportHydrusData() { using (var context = new JizanOMSContext()) { try { GetOMS.OMSFolder(); GetLatest(); ToBackup.MoveMD(); //string strPath = Environment.GetFolderPath( // System.Environment.SpecialFolder.DesktopDirectory); string strPath = @"C:\JizHydrusLatest\"; var extractMeter1 = context.Database .SqlQuery <HydrusData>("SELECT * FROM viewLatestHydrusData WHERE ReadingDate IS NOT NULL"); var extractMeter2 = context.Database .SqlQuery <HydrusData>("SELECT * FROM viewLatestHydrusData WHERE ReadingDate IS NULL"); var fileName = Timex.CurrentTime(); string path2 = strPath + "\\" + "HYDRUS_DATA_" + fileName + ".csv"; using (StreamWriter writer = new StreamWriter(path2, false)) { string[] separator = { "," }; var filecontents = new StringBuilder(); filecontents.Append("#, Account No, Area No, Area Name, Serial No, RAW_TELEGRAM, READING_DATE\r\n"); string extract = null; foreach (var em in extractMeter1) { extract += em.RowNum + ","; //# extract += em.AccountNo + ","; //AccountNo extract += em.AreaNo + ","; //AreaNo extract += em.AreaName + ","; //AreaName extract += em.MeterAddress + ","; //SerialNo extract += em.RawTelegram + ","; //Packet extract += em.ReadingDate .ToString() .DBtoCSVDateConvert(); //Date extract += "\r\n"; } foreach (var em in extractMeter2) { extract += em.RowNum + ","; //# extract += em.AccountNo + ","; //AccountNo extract += em.AreaNo + ","; //AreaNo extract += em.AreaName + ","; //AreaName extract += em.MeterAddress + ","; //SerialNo extract += em.RawTelegram + ","; //Packet extract += em.ReadingDate; //Date extract += "\r\n"; } filecontents.Append(extract); writer.Write(filecontents.ToString()); writer.Flush(); writer.Close(); } //Console.WriteLine("Extracted Hydrus Data"); Console.WriteLine("Extracted Hydrus Data in JizHydrusLatest Folder."); } catch (Exception e) { Console.WriteLine(e); //return; } } }
private static void GetLatest() { if (!Directory.Exists(@"C:\JizHydrusLatest\")) { Directory.CreateDirectory(@"C:\JizHydrusLatest\"); } //try //{ var gateway = Gateway.GatewayList(); //delete all latest here var result = Delete.LatestReading(); Console.WriteLine($"Delete {result}"); foreach (var g in gateway) { //var x = context.GetLatestMeterReading(g.Name); Exec.LatestReading(g); //Console.WriteLine(x); //var extractMeter = context.Database // .SqlQuery<CustomLatest>("SELECT DISTINCT MeterAddress, ReadingDate, RawTelegram FROM tblLatest WHERE GatewayId=@GatewayId", // new SqlParameter("@GatewayId", g.Name)); var extractMeter = Get.LatestReading(g); var fileName = Timex.CurrentTime(); string path2 = @"C:\JizHydrusLatest\" + g + "\\" + fileName + ".csv"; if (!Directory.Exists(@"C:\JizHydrusLatest\" + g + "\\")) { Directory.CreateDirectory(@"C:\JizHydrusLatest\" + g + "\\"); } using (StreamWriter writer = new StreamWriter(path2, false)) { string[] separator = { "," }; var filecontents = new StringBuilder(); filecontents.Append("METER_ADDRESS, READING_DATE, PACKET\r\n"); string extract = null; foreach (DataRow em in extractMeter.Tables["MeterReading"].Rows) { extract += em["MeterAddress"] + ","; //Serial extract += em["ReadingDate"] .ToString() .DBtoCSVDateConvert() + ","; //Date extract += em["RawTelegram"]; //Packet extract += "\r\n"; } filecontents.Append(extract); writer.Write(filecontents.ToString()); writer.Flush(); writer.Close(); } } Console.WriteLine("Extracted"); //} //catch (Exception exception) //{ // Console.WriteLine(exception); // throw; //} }