private string FindNextParagraphSpeaker(IList <ICoreMap> paragraph, int paragraphOffset, Dictionaries dict) { ICoreMap lastSent = paragraph[paragraph.Count - 1]; string speaker = string.Empty; foreach (CoreLabel w in lastSent.Get(typeof(CoreAnnotations.TokensAnnotation))) { if (w.Get(typeof(CoreAnnotations.LemmaAnnotation)).Equals("report") || w.Get(typeof(CoreAnnotations.LemmaAnnotation)).Equals("say")) { string word = w.Get(typeof(CoreAnnotations.TextAnnotation)); SemanticGraph dependency = lastSent.Get(typeof(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation)); IndexedWord t = dependency.GetNodeByWordPattern(word); foreach (Pair <GrammaticalRelation, IndexedWord> child in dependency.ChildPairs(t)) { if (child.First().GetShortName().Equals("nsubj")) { int subjectIndex = child.Second().Index(); // start from 1 IntTuple headPosition = new IntTuple(2); headPosition.Set(0, paragraph.Count - 1 + paragraphOffset); headPosition.Set(1, subjectIndex - 1); if (mentionheadPositions.Contains(headPosition) && mentionheadPositions[headPosition].nerString.StartsWith("PER")) { speaker = int.ToString(mentionheadPositions[headPosition].mentionID); } } } } } return(speaker); }
public TempPouzitieModulu(int nIdModul, IntTuple nSur, String nId, String nMenoModulu) { idModul = nIdModul; sur = nSur; id = nId; menoModulu = nMenoModulu; }
static long Solve(long n, IntTuple g, IntTuple s, IntTuple b) { if (g.Item1 >= g.Item2) { return(Solve(n, s, b)); } if (s.Item1 >= s.Item2) { return(Solve(n, g, b)); } if (b.Item1 >= b.Item2) { return(Solve(n, g, s)); } long max = 0; long currentEffort = 0; while (n >= 0) { max = Max(max, currentEffort + Solve(n, g, s)); n -= b.Item1; currentEffort += b.Item2; } return(max); }
Objekt nacitajOp(String id) { String op = popToken(); IntTuple sur = getTagIntTuple(); if (op == "index") { return(new Index(sur.a, sur.b, id)); } if (op == "concat") { return(new Zretazenie(sur.a, sur.b, id)); } if (op == "reverse") { return(new OtocenieBitov(sur.a, sur.b, id)); } if (op == "inc" || op == "dec") { return(new IncDecOperacia(sur.a, sur.b, id, op)); } if (op == "mod") { return(new Modulo(sur.a, sur.b, id)); } if (op == "if") { IntTuple sur2 = getIntTuple(); return(new IfBlok(sur.a, sur.b, sur2.a, sur2.b, id)); } return(new Operacia(sur.a, sur.b, id, op)); }
/// <summary>initialize positions and corefClusters (put each mention in each CorefCluster)</summary> private void InitializeCorefCluster() { for (int i = 0; i < predictedOrderedMentionsBySentence.Count; i++) { for (int j = 0; j < predictedOrderedMentionsBySentence[i].Count; j++) { Mention m = predictedOrderedMentionsBySentence[i][j]; if (allPredictedMentions.Contains(m.mentionID)) { SieveCoreferenceSystem.logger.Warning("WARNING: Already contain mention " + m.mentionID); Mention m1 = allPredictedMentions[m.mentionID]; SieveCoreferenceSystem.logger.Warning("OLD mention: " + m1.SpanToString() + "[" + m1.startIndex + "," + m1.endIndex + "]"); SieveCoreferenceSystem.logger.Warning("NEW mention: " + m.SpanToString() + "[" + m.startIndex + "," + m.endIndex + "]"); } // SieveCoreferenceSystem.debugPrintMentions(System.err, "PREDICTED ORDERED", predictedOrderedMentionsBySentence); // SieveCoreferenceSystem.debugPrintMentions(System.err, "GOLD ORDERED", goldOrderedMentionsBySentence); System.Diagnostics.Debug.Assert((!allPredictedMentions.Contains(m.mentionID))); allPredictedMentions[m.mentionID] = m; IntTuple pos = new IntTuple(2); pos.Set(0, i); pos.Set(1, j); positions[m] = pos; m.sentNum = i; System.Diagnostics.Debug.Assert((!corefClusters.Contains(m.mentionID))); corefClusters[m.mentionID] = new CorefCluster(m.mentionID, Generics.NewHashSet(Java.Util.Collections.SingletonList(m))); m.corefClusterID = m.mentionID; IntTuple headPosition = new IntTuple(2); headPosition.Set(0, i); headPosition.Set(1, m.headIndex); mentionheadPositions[headPosition] = m; } } }
static long Solve(long n, IntTuple g) { if (g.Item1 >= g.Item2) { return(n); } return(n % g.Item1 + (n / g.Item1) * g.Item2); }
/// <summary>the feature number of the original feature or -1 if this is for a prior</summary> internal virtual int FeatureOf(int index) { IntTuple i = featureIndex.Get(index); if (i.Length() == 1) { return(-1); } return(i.Get(1)); }
// for backward compatibility with a few old things // TODO: Aim to get rid of this entirely private static void AddObsoleteCoreferenceAnnotations(Annotation annotation, IList <IList <Mention> > orderedMentions, IDictionary <int, CorefChain> result) { IList <Pair <IntTuple, IntTuple> > links = SieveCoreferenceSystem.GetLinks(result); // // save the coref output as CorefGraphAnnotation // // cdm 2013: this block didn't seem to be doing anything needed.... // List<List<CoreLabel>> sents = new ArrayList<List<CoreLabel>>(); // for (CoreMap sentence: annotation.get(CoreAnnotations.SentencesAnnotation.class)) { // List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class); // sents.add(tokens); // } // this graph is stored in CorefGraphAnnotation -- the raw links found by the coref system IList <Pair <IntTuple, IntTuple> > graph = new List <Pair <IntTuple, IntTuple> >(); foreach (Pair <IntTuple, IntTuple> link in links) { // // Note: all offsets in the graph start at 1 (not at 0!) // we do this for consistency reasons, as indices for syntactic dependencies start at 1 // int srcSent = link.first.Get(0); int srcTok = orderedMentions[srcSent - 1][link.first.Get(1) - 1].headIndex + 1; int dstSent = link.second.Get(0); int dstTok = orderedMentions[dstSent - 1][link.second.Get(1) - 1].headIndex + 1; IntTuple dst = new IntTuple(2); dst.Set(0, dstSent); dst.Set(1, dstTok); IntTuple src = new IntTuple(2); src.Set(0, srcSent); src.Set(1, srcTok); graph.Add(new Pair <IntTuple, IntTuple>(src, dst)); } annotation.Set(typeof(CorefCoreAnnotations.CorefGraphAnnotation), graph); foreach (CorefChain corefChain in result.Values) { if (corefChain.GetMentionsInTextualOrder().Count < 2) { continue; } ICollection <CoreLabel> coreferentTokens = Generics.NewHashSet(); foreach (CorefChain.CorefMention mention in corefChain.GetMentionsInTextualOrder()) { ICoreMap sentence = annotation.Get(typeof(CoreAnnotations.SentencesAnnotation))[mention.sentNum - 1]; CoreLabel token = sentence.Get(typeof(CoreAnnotations.TokensAnnotation))[mention.headIndex - 1]; coreferentTokens.Add(token); } foreach (CoreLabel token_1 in coreferentTokens) { token_1.Set(typeof(CorefCoreAnnotations.CorefClusterAnnotation), coreferentTokens); } } }
public void setIntTuplesWithSwapsAndSignChange(IntTuple[] inputIntTuples, IntTupleEqualityComparer comparer) { HashSet<IntTuple> container = new HashSet<IntTuple>(comparer); foreach (var intTuple in inputIntTuples) { container.Add(intTuple); addOppositeElements(container, intTuple); addSwapElements(container); } this.intTuples = new IntTuple[container.Count]; container.CopyTo(this.intTuples); }
private bool FindSpeaker(int utterNum, int sentNum, IList <ICoreMap> sentences, int startIndex, int endIndex, Dictionaries dict) { IList <CoreLabel> sent = sentences[sentNum].Get(typeof(CoreAnnotations.TokensAnnotation)); for (int i = startIndex; i < endIndex; i++) { if (sent[i].Get(typeof(CoreAnnotations.UtteranceAnnotation)) != 0) { continue; } string lemma = sent[i].Get(typeof(CoreAnnotations.LemmaAnnotation)); string word = sent[i].Get(typeof(CoreAnnotations.TextAnnotation)); if (dict.reportVerb.Contains(lemma)) { // find subject SemanticGraph dependency = sentences[sentNum].Get(typeof(SemanticGraphCoreAnnotations.EnhancedDependenciesAnnotation)); IndexedWord w = dependency.GetNodeByWordPattern(word); if (w != null) { foreach (Pair <GrammaticalRelation, IndexedWord> child in dependency.ChildPairs(w)) { if (child.First().GetShortName().Equals("nsubj")) { string subjectString = child.Second().Word(); int subjectIndex = child.Second().Index(); // start from 1 IntTuple headPosition = new IntTuple(2); headPosition.Set(0, sentNum); headPosition.Set(1, subjectIndex - 1); string speaker; if (mentionheadPositions.Contains(headPosition)) { speaker = int.ToString(mentionheadPositions[headPosition].mentionID); } else { speaker = subjectString; } speakers[utterNum] = speaker; return(true); } } } else { SieveCoreferenceSystem.logger.Warning("Cannot find node in dependency for word " + word); } } } return(false); }
private static void AnnotateOldFormat(IDictionary <int, CorefChain> result, Document corefDoc) { IList <Pair <IntTuple, IntTuple> > links = GetLinks(result); Annotation annotation = corefDoc.annotation; // // save the coref output as CorefGraphAnnotation // // this graph is stored in CorefGraphAnnotation -- the raw links found by the coref system IList <Pair <IntTuple, IntTuple> > graph = new List <Pair <IntTuple, IntTuple> >(); foreach (Pair <IntTuple, IntTuple> link in links) { // // Note: all offsets in the graph start at 1 (not at 0!) // we do this for consistency reasons, as indices for syntactic dependencies start at 1 // int srcSent = link.first.Get(0); int srcTok = corefDoc.GetOrderedMentions()[srcSent - 1][link.first.Get(1) - 1].headIndex + 1; int dstSent = link.second.Get(0); int dstTok = corefDoc.GetOrderedMentions()[dstSent - 1][link.second.Get(1) - 1].headIndex + 1; IntTuple dst = new IntTuple(2); dst.Set(0, dstSent); dst.Set(1, dstTok); IntTuple src = new IntTuple(2); src.Set(0, srcSent); src.Set(1, srcTok); graph.Add(new Pair <IntTuple, IntTuple>(src, dst)); } annotation.Set(typeof(CorefCoreAnnotations.CorefGraphAnnotation), graph); foreach (CorefChain corefChain in result.Values) { if (corefChain.GetMentionsInTextualOrder().Count < 2) { continue; } ICollection <CoreLabel> coreferentTokens = Generics.NewHashSet(); foreach (CorefChain.CorefMention mention in corefChain.GetMentionsInTextualOrder()) { ICoreMap sentence = annotation.Get(typeof(CoreAnnotations.SentencesAnnotation))[mention.sentNum - 1]; CoreLabel token = sentence.Get(typeof(CoreAnnotations.TokensAnnotation))[mention.headIndex - 1]; coreferentTokens.Add(token); } foreach (CoreLabel token_1 in coreferentTokens) { token_1.Set(typeof(CorefCoreAnnotations.CorefClusterAnnotation), coreferentTokens); } } }
/// <summary>This constructor is used to recreate a CorefMention following serialization.</summary> public CorefMention(Dictionaries.MentionType mentionType, Dictionaries.Number number, Dictionaries.Gender gender, Dictionaries.Animacy animacy, int startIndex, int endIndex, int headIndex, int corefClusterID, int mentionID, int sentNum, IntTuple position, string mentionSpan) { this.mentionType = mentionType; this.number = number; this.gender = gender; this.animacy = animacy; this.startIndex = startIndex; this.endIndex = endIndex; this.headIndex = headIndex; this.corefClusterID = corefClusterID; this.mentionID = mentionID; this.sentNum = sentNum; this.position = position; this.mentionSpan = mentionSpan; }
/// <summary> /// This method return such int tuple where the components of this tuple have ascending order. /// </summary> /// <param name="num"></param> /// <returns></returns> public IntTuple[] applyCornacchiaMethod(int num) { IntTuple[] intTuples; if (num == 1) { intTuples = new IntTuple[] { new IntTuple() { Tuple = new int[] { 1, 0 } }, new IntTuple() { Tuple = new int[] { 0, 1 } } }; } else { List<IntTuple> intTuplesOfFactors = listSumOfSquaresOfFactors(num); intTuples = applyFibonacciIdentity(intTuplesOfFactors); } return intTuples; }
private void addNumMultipleForLaterNum(int limit, List<IntTuple>[] dictOfSolutions, int num, IntTuple[] currentTuples) { foreach (var intTuple in currentTuples) { int k = 2; while (num <= (double)limit / (double)(k * k)) { int laterNum = num * k * k; IntTuple tupleForLaterNum = new IntTuple() { Tuple = new int[] { intTuple.Tuple[0] * k, intTuple.Tuple[1] * k } }; updateTuplesOfLaterNum(dictOfSolutions, laterNum, tupleForLaterNum); k++; laterNum = num * k * k; } } }
private string FindParagraphSpeaker(IList <ICoreMap> paragraph, int paragraphUtterIndex, string nextParagraphSpeaker, int paragraphOffset, Dictionaries dict) { if (!speakers.Contains(paragraphUtterIndex)) { if (!nextParagraphSpeaker.Equals(string.Empty)) { speakers[paragraphUtterIndex] = nextParagraphSpeaker; } else { // find the speaker of this paragraph (John, nbc news) ICoreMap lastSent = paragraph[paragraph.Count - 1]; string speaker = string.Empty; bool hasVerb = false; for (int i = 0; i < lastSent.Get(typeof(CoreAnnotations.TokensAnnotation)).Count; i++) { CoreLabel w = lastSent.Get(typeof(CoreAnnotations.TokensAnnotation))[i]; string pos = w.Get(typeof(CoreAnnotations.PartOfSpeechAnnotation)); string ner = w.Get(typeof(CoreAnnotations.NamedEntityTagAnnotation)); if (pos.StartsWith("V")) { hasVerb = true; break; } if (ner.StartsWith("PER")) { IntTuple headPosition = new IntTuple(2); headPosition.Set(0, paragraph.Count - 1 + paragraphOffset); headPosition.Set(1, i); if (mentionheadPositions.Contains(headPosition)) { speaker = int.ToString(mentionheadPositions[headPosition].mentionID); } } } if (!hasVerb && !speaker.Equals(string.Empty)) { speakers[paragraphUtterIndex] = speaker; } } } return(FindNextParagraphSpeaker(paragraph, paragraphOffset, dict)); }
private void addOppositeElements(HashSet<IntTuple> tempIntTuples, IntTuple intTuple) { int dim = intTuple.Tuple.Length; // The following loop iterates over the all sign-combinations of the original tuple components. // E.g. for (x,y) these are (-x,y),(x,-y),(-x,-y) for (int signDealingOut = 1; signDealingOut < Math.Pow(2, dim); signDealingOut++) { int[] currentTuple = new int[dim]; for (int idx = 0; idx < dim; idx++) { int bit = (signDealingOut >> idx) & 1; if (bit == 0) // the bit 0 symbolizes '+' currentTuple[idx] = intTuple.Tuple[idx]; else // the bit 0 symbolizes '-' currentTuple[idx] = -intTuple.Tuple[idx]; } tempIntTuples.Add(new IntTuple() { Tuple = currentTuple }); } }
/// <summary>This constructor builds the external CorefMention class from the internal Mention.</summary> public CorefMention(Mention m, IntTuple pos) { mentionType = m.mentionType; number = m.number; gender = m.gender; animacy = m.animacy; startIndex = m.startIndex + 1; endIndex = m.endIndex + 1; headIndex = m.headIndex + 1; corefClusterID = m.corefClusterID; sentNum = m.sentNum + 1; mentionID = m.mentionID; mentionSpan = m.SpanToString(); // index starts from 1 position = new IntTuple(2); position.Set(0, pos.Get(0) + 1); position.Set(1, pos.Get(1) + 1); m.headWord.Set(typeof(CorefCoreAnnotations.CorefClusterIdAnnotation), corefClusterID); }
private IntTuple[] innerDecomposeByBacktracking(int num, int squaresNO) { IntTuple[] intTuples; if (num == 0) { int[] tuple = new int[squaresNO]; for (int idx = 0; idx < squaresNO; idx++) { tuple[idx] = 0; } intTuples = new IntTuple[1] { new IntTuple() { Tuple = tuple } }; } else if (squaresNO == 2) intTuples = cornacchiaMethod.applyCornacchiaMethod(num); else { intTuples = innerDecomposeByBacktrackingWhenSquaresNOIsGreaterThanTwo(num, squaresNO); } return intTuples; }
static long Solve(long n, IntTuple g, IntTuple s) { if (g.Item1 >= g.Item2) { Solve(n, s); } if (s.Item1 >= s.Item2) { Solve(n, g); } long max = 0; long currentEffort = 0; while (n >= 0) { max = Max(max, currentEffort + Solve(n, g)); n -= s.Item1; currentEffort += s.Item2; } return(max); }
/// <summary> /// This method return such int tuple where the components of this tuple have ascending order. /// </summary> /// <param name="num"></param> /// <param name="squaresNO"></param> /// <returns></returns> public IntTuple[] decomposeByBacktracking(int num, int squaresNO) { IntTuple[] decompositions; if (squaresNO == 1) { int floorOfSquareOfN = (int)Math.Floor(Math.Sqrt(num)); if (floorOfSquareOfN * floorOfSquareOfN == num) { decompositions = new IntTuple[1]; decompositions[0] = new IntTuple() { Tuple = new int[] { floorOfSquareOfN } }; } else decompositions = new IntTuple[0]; } else if (squaresNO >= 2) { decompositions = innerDecomposeByBacktracking(num, squaresNO); } else decompositions = new IntTuple[0]; return decompositions; }
private void updateTuplesOfLaterNum(List<IntTuple>[] dictOfSolutions, int laterNum, IntTuple tupleForLaterNum) { if (dictOfSolutions[laterNum] != null) dictOfSolutions[laterNum].Add(tupleForLaterNum); else { dictOfSolutions[laterNum] = new List<IntTuple>(); dictOfSolutions[laterNum].Add(tupleForLaterNum); } }
/// <summary>Extract gold coref link information</summary> protected internal virtual void ExtractGoldLinks() { // List<List<Mention>> orderedMentionsBySentence = this.getOrderedMentions(); IList <Pair <IntTuple, IntTuple> > links = new List <Pair <IntTuple, IntTuple> >(); // position of each mention in the input matrix, by id IDictionary <int, IntTuple> positions = Generics.NewHashMap(); // positions of antecedents IDictionary <int, IList <IntTuple> > antecedents = Generics.NewHashMap(); for (int i = 0; i < goldOrderedMentionsBySentence.Count; i++) { for (int j = 0; j < goldOrderedMentionsBySentence[i].Count; j++) { Mention m = goldOrderedMentionsBySentence[i][j]; int id = m.mentionID; IntTuple pos = new IntTuple(2); pos.Set(0, i); pos.Set(1, j); positions[id] = pos; antecedents[id] = new List <IntTuple>(); } } // SieveCoreferenceSystem.debugPrintMentions(System.err, "", goldOrderedMentionsBySentence); foreach (IList <Mention> mentions in goldOrderedMentionsBySentence) { foreach (Mention m in mentions) { int id = m.mentionID; IntTuple src = positions[id]; System.Diagnostics.Debug.Assert((src != null)); if (m.originalRef >= 0) { IntTuple dst = positions[m.originalRef]; if (dst == null) { throw new Exception("Cannot find gold mention with ID=" + m.originalRef); } // to deal with cataphoric annotation while (dst.Get(0) > src.Get(0) || (dst.Get(0) == src.Get(0) && dst.Get(1) > src.Get(1))) { Mention dstMention = goldOrderedMentionsBySentence[dst.Get(0)][dst.Get(1)]; m.originalRef = dstMention.originalRef; dstMention.originalRef = id; if (m.originalRef < 0) { break; } dst = positions[m.originalRef]; } if (m.originalRef < 0) { continue; } // A B C: if A<-B, A<-C => make a link B<-C for (int k = dst.Get(0); k <= src.Get(0); k++) { for (int l = 0; l < goldOrderedMentionsBySentence[k].Count; l++) { if (k == dst.Get(0) && l < dst.Get(1)) { continue; } if (k == src.Get(0) && l > src.Get(1)) { break; } IntTuple missed = new IntTuple(2); missed.Set(0, k); missed.Set(1, l); if (links.Contains(new Pair <IntTuple, IntTuple>(missed, dst))) { antecedents[id].Add(missed); links.Add(new Pair <IntTuple, IntTuple>(src, missed)); } } } links.Add(new Pair <IntTuple, IntTuple>(src, dst)); System.Diagnostics.Debug.Assert((antecedents[id] != null)); antecedents[id].Add(dst); IList <IntTuple> ants = antecedents[m.originalRef]; System.Diagnostics.Debug.Assert((ants != null)); foreach (IntTuple ant in ants) { antecedents[id].Add(ant); links.Add(new Pair <IntTuple, IntTuple>(src, ant)); } } } } goldLinks = links; }
private static MapSquare ReadMapSquare(IntTuple tuple) => tuple.Values.Length switch { 3 => new MapSquare(
private static extern IntTuple flip_things_around(IntTuple t);
public void nacitajDWKod() { while (a.token != "") { if (isToken("]")) { return; } if (isToken("def")) { String fMeno = popToken(); getToken("["); objekty = new Dictionary <String, Objekt>(); registre = new List <RegisterInfo>(); vstupy = new List <BodkaInfo>(); vystupy = new List <BodkaInfo>(); nacitajDWKod(); Modul f = new Modul(fMeno, objekty, vstupy, vystupy, registre, poleBodiek, poleIndexov); poleBodiek = null; poleIndexov = null; moduly.Add(f); if (f.meno != "main") { Projekt.DATABAZA[f.meno] = new ObjektInfo(f.meno, f.meno, vstupy, vystupy); } } else if (isToken("input")) { String vstup = popToken(); IntTuple bit = getTagIntTuple(); vstupy.Add(new BodkaInfo(vstup, bit.a, false, bit.b, false)); } else if (isToken("output")) { String vystup = popToken(); IntTuple bit = getTagIntTuple(); vystupy.Add(new BodkaInfo(vystup, bit.a, false, bit.b, false)); } else if (isToken("register")) { String register = popToken(); IntTuple bit = getTagIntTuple(); registre.Add(new RegisterInfo(register, bit.a, bit.b)); } else if (isToken("#")) { nacitajGraf(); } else { getToken("{"); String id = popToken(); getToken("}"); if (isToken("call") || isToken("use")) { String menoModulu = popToken(); IntTuple sur = getTagIntTuple(); volania.Add(new TempPouzitieModulu(moduly.Count, sur, id, menoModulu)); } else if (isToken("const")) { List <String> values = new List <String>(); getToken("("); while (!isToken(")")) { values.Add(popToken()); } IntTuple bit = getTagIntTuple(); IntTuple sur = getTagIntTuple(); objekty[id] = new Konst(sur.a, sur.b, id, "const", bit.a, bit.b, values.ToArray()); } else if (isToken("in")) { String io = popToken(); IntTuple sur = getTagIntTuple(); BodkaInfo b = getVstup(io); objekty[id] = new IoOperacia(sur.a, sur.b, id, "in", b); } else if (isToken("out")) { String io = popToken(); IntTuple sur = getTagIntTuple(); BodkaInfo b = getVystup(io); objekty[id] = new IoOperacia(sur.a, sur.b, id, "out", b); } else if (isToken("regC")) { String register = popToken(); IntTuple sur = getTagIntTuple(); RegisterInfo r = getRegister(register); objekty[id] = new RegisterC(sur.a, sur.b, id, r); } else if (isToken("regZ")) { String register = popToken(); IntTuple sur = getTagIntTuple(); RegisterInfo r = getRegister(register); objekty[id] = new RegisterZ(sur.a, sur.b, id, r); } else if (isToken("regZ_index")) { String register = popToken(); IntTuple sur = getTagIntTuple(); RegisterInfo r = getRegister(register); objekty[id] = new RegisterZIndex(sur.a, sur.b, id, r); } else if (isToken("change")) { IntTuple bit = getTagIntTuple(); IntTuple sur = getTagIntTuple(); objekty[id] = new ZmenaBitov(sur.a, sur.b, id, bit.a, bit.b); } else { objekty[id] = nacitajOp(id); } } } }
/// <summary>Loads the CorefChain objects from the serialized buffer.</summary> /// <param name="reader">the buffer</param> /// <returns>A map from cluster id to clusters</returns> /// <exception cref="System.IO.IOException"/> private static IDictionary <int, CorefChain> LoadCorefChains(BufferedReader reader) { string line = reader.ReadLine().Trim(); if (line.IsEmpty()) { return(null); } int clusterCount = System.Convert.ToInt32(line); IDictionary <int, CorefChain> chains = Generics.NewHashMap(); // read each cluster for (int c = 0; c < clusterCount; c++) { line = reader.ReadLine().Trim(); string[] bits = line.Split("\\s"); int cid = System.Convert.ToInt32(bits[0]); int mentionCount = System.Convert.ToInt32(bits[1]); IDictionary <IntPair, ICollection <CorefChain.CorefMention> > mentionMap = Generics.NewHashMap(); CorefChain.CorefMention representative = null; // read each mention in this cluster for (int m = 0; m < mentionCount; m++) { line = reader.ReadLine(); bits = line.Split("\\s"); IntPair key = new IntPair(System.Convert.ToInt32(bits[0]), System.Convert.ToInt32(bits[1])); bool rep = bits[2].Equals("1"); Dictionaries.MentionType mentionType = ParseMentionType(bits[3]); Dictionaries.Number number = ParseNumber(bits[4]); Dictionaries.Gender gender = ParseGender(bits[5]); Dictionaries.Animacy animacy = ParseAnimacy(bits[6]); int startIndex = System.Convert.ToInt32(bits[7]); int endIndex = System.Convert.ToInt32(bits[8]); int headIndex = System.Convert.ToInt32(bits[9]); int clusterID = System.Convert.ToInt32(bits[10]); int mentionID = System.Convert.ToInt32(bits[11]); int sentNum = System.Convert.ToInt32(bits[12]); int posLen = System.Convert.ToInt32(bits[13]); int[] posElems = new int[posLen]; for (int i = 0; i < posLen; i++) { posElems[i] = System.Convert.ToInt32(bits[14 + i]); } IntTuple position = new IntTuple(posElems); string span = UnescapeSpace(bits[14 + posLen]); CorefChain.CorefMention mention = new CorefChain.CorefMention(mentionType, number, gender, animacy, startIndex, endIndex, headIndex, clusterID, mentionID, sentNum, position, span); ICollection <CorefChain.CorefMention> mentionsWithThisHead = mentionMap[key]; if (mentionsWithThisHead == null) { mentionsWithThisHead = Generics.NewHashSet(); mentionMap[key] = mentionsWithThisHead; } mentionsWithThisHead.Add(mention); if (rep) { representative = mention; } } // construct the cluster CorefChain chain = new CorefChain(cid, mentionMap, representative); chains[cid] = chain; } reader.ReadLine(); return(chains); }
static void Main() { int n = Read(); int m = Read(); IntTuple[] edges = new IntTuple[m]; for (int i = 0; i < edges.Length; i++) { edges[i] = new IntTuple(Read() - 1, Read() - 1); } //???????? IntTuple[] currentColor = new IntTuple[n]; IntTuple[][] colors = new IntTuple[n][]; IntTuple[][] nextColors = new IntTuple[n][]; //11*10^5 for (int i = 0; i < colors.Length; i++) { colors[i] = new IntTuple[11]; nextColors[i] = new IntTuple[11]; } //????????????????????? //10^5 var q = Read(); for (int i = 1; i <= q; i++) { var v = Read() - 1; var d = Read(); var c = Read(); colors[v][d] = new IntTuple(c, i); currentColor[v] = new IntTuple(c, i); } //10*(3*10^6) for (int i = 1; i <= 10; i++) { for (int j = 0; j < nextColors.Length; j++) { nextColors[j] = new IntTuple[11 - i]; } for (int index = 0; index < edges.Length; index++) { var edge = edges[index]; for (int j = 0; j < nextColors[edge.Item1].Length; j++) { if (nextColors[edge.Item1][j].Item2 < colors[edge.Item2][j + 1].Item2) { nextColors[edge.Item1][j] = colors[edge.Item2][j + 1]; } if (nextColors[edge.Item2][j].Item2 < colors[edge.Item1][j + 1].Item2) { nextColors[edge.Item2][j] = colors[edge.Item1][j + 1]; } } } var tmp = colors; colors = nextColors; nextColors = tmp; for (int j = 0; j < colors.Length; j++) { var currentNewest = new IntTuple(); for (int k = 0; k < colors[j].Length; k++) { if (currentNewest.Item2 < colors[j][k].Item2) { currentNewest = colors[j][k]; } } if (currentColor[j].Item2 < currentNewest.Item2) { currentColor[j] = currentNewest; } } } Console.WriteLine(string.Join("\n", currentColor.Select(x => x.Item1))); }
private float FloodFill(int w, int h, bool[,] vsides, bool[,] hsides, List <Rect> drawRects, int fillx1, int filly1, out bool containsBaddy, Qix theQix) { float nArea = 0.0f; Queue <IntTuple> queue = new Queue <IntTuple>(); bool[,] floodRects = new bool[w - 1, h - 1]; queue.Enqueue(new IntTuple(fillx1, filly1)); containsBaddy = false; while (queue.Count > 0) { IntTuple tuple = queue.Dequeue(); if (!floodRects[tuple.x, tuple.y]) { floodRects[tuple.x, tuple.y] = true; Rect rect = new Rect(xVector3s[tuple.x], yVector3s[tuple.y], xVector3s[tuple.x + 1] - xVector3s[tuple.x], yVector3s[tuple.y + 1] - yVector3s[tuple.y]); drawRects.Add(rect); if (!containsBaddy && rect.Contains(theQix.position)) { containsBaddy = true; } nArea += ((xVector3s[tuple.x + 1] - xVector3s[tuple.x]) * (yVector3s[tuple.y + 1] - yVector3s[tuple.y])); if ((tuple.x > 0) && (!vsides[tuple.x - 1, tuple.y])) { // Can move left JustLog("Left->(" + (tuple.x - 1) + "," + tuple.y + ")"); queue.Enqueue(new IntTuple(tuple.x - 1, tuple.y)); } if ((tuple.x < (w - 2)) && (!vsides[tuple.x, tuple.y])) { // Can move right JustLog("Right->(" + (tuple.x + 1) + "," + tuple.y + ")"); queue.Enqueue(new IntTuple(tuple.x + 1, tuple.y)); } if ((tuple.y > 0) && (!hsides[tuple.x, tuple.y - 1])) { // Can move down JustLog("Down->(" + tuple.x + "," + (tuple.y - 1) + ")"); queue.Enqueue(new IntTuple(tuple.x, tuple.y - 1)); } if ((tuple.y < (h - 2)) && (!hsides[tuple.x, tuple.y])) { // Can move up JustLog("Up->(" + tuple.x + "," + (tuple.y + 1) + ")"); queue.Enqueue(new IntTuple(tuple.x, tuple.y + 1)); } } } return(nArea); }
private HashSet<IntTuple> applyFibonacciIdentity(HashSet<IntTuple> currentIntTuples, IntTuple newIntTuple) { HashSet<IntTuple> result = new HashSet<IntTuple>(comparer); if (currentIntTuples.Count == 0) result.Add(newIntTuple); else { foreach (var currentIntTuple in currentIntTuples) { int n1, n2; int a = currentIntTuple.Tuple[0]; int b = currentIntTuple.Tuple[1]; int c = newIntTuple.Tuple[0]; int d = newIntTuple.Tuple[1]; n1 = (int)Math.Abs(a * c - b * d); n2 = (int)Math.Abs(a * d + b * c); chooseOrderedIntTuple(result, n1, n2); n1 = (int)Math.Abs(a * c + b * d); n2 = (int)Math.Abs(a * d - b * c); chooseOrderedIntTuple(result, n1, n2); } } return result; }
internal virtual int ClassOf(int index) { IntTuple i = featureIndex.Get(index); return(i.Get(0)); }
/// <exception cref="System.IO.IOException"/> public override Pair <Annotation, InputStream> Read(InputStream @is) { if (compress && !(@is is GZIPInputStream)) { @is = new GZIPInputStream(@is); } BufferedReader reader = new BufferedReader(new InputStreamReader(@is)); Annotation doc = new Annotation(string.Empty); string line; // read the coref graph (new format) IDictionary <int, CorefChain> chains = LoadCorefChains(reader); if (chains != null) { doc.Set(typeof(CorefCoreAnnotations.CorefChainAnnotation), chains); } // read the coref graph (old format) line = reader.ReadLine().Trim(); if (line.Length > 0) { string[] bits = line.Split(" "); if (bits.Length % 4 != 0) { throw new RuntimeIOException("ERROR: Incorrect format for the serialized coref graph: " + line); } IList <Pair <IntTuple, IntTuple> > corefGraph = new List <Pair <IntTuple, IntTuple> >(); for (int i = 0; i < bits.Length; i += 4) { IntTuple src = new IntTuple(2); IntTuple dst = new IntTuple(2); src.Set(0, System.Convert.ToInt32(bits[i])); src.Set(1, System.Convert.ToInt32(bits[i + 1])); dst.Set(0, System.Convert.ToInt32(bits[i + 2])); dst.Set(1, System.Convert.ToInt32(bits[i + 3])); corefGraph.Add(new Pair <IntTuple, IntTuple>(src, dst)); } doc.Set(typeof(CorefCoreAnnotations.CorefGraphAnnotation), corefGraph); } // read individual sentences IList <ICoreMap> sentences = new List <ICoreMap>(); while ((line = reader.ReadLine()) != null) { ICoreMap sentence = new Annotation(string.Empty); // first line is the parse tree. construct it with CoreLabels in Tree nodes Tree tree = new PennTreeReader(new StringReader(line), new LabeledScoredTreeFactory(CoreLabel.Factory())).ReadTree(); sentence.Set(typeof(TreeCoreAnnotations.TreeAnnotation), tree); // read the dependency graphs AnnotationSerializer.IntermediateSemanticGraph intermCollapsedDeps = LoadDependencyGraph(reader); AnnotationSerializer.IntermediateSemanticGraph intermUncollapsedDeps = LoadDependencyGraph(reader); AnnotationSerializer.IntermediateSemanticGraph intermCcDeps = LoadDependencyGraph(reader); // the remaining lines until empty line are tokens IList <CoreLabel> tokens = new List <CoreLabel>(); while ((line = reader.ReadLine()) != null) { if (line.Length == 0) { break; } CoreLabel token = LoadToken(line, haveExplicitAntecedent); tokens.Add(token); } sentence.Set(typeof(CoreAnnotations.TokensAnnotation), tokens); // convert the intermediate graph to an actual SemanticGraph SemanticGraph collapsedDeps = intermCollapsedDeps.ConvertIntermediateGraph(tokens); sentence.Set(typeof(SemanticGraphCoreAnnotations.CollapsedDependenciesAnnotation), collapsedDeps); SemanticGraph uncollapsedDeps = intermUncollapsedDeps.ConvertIntermediateGraph(tokens); sentence.Set(typeof(SemanticGraphCoreAnnotations.BasicDependenciesAnnotation), uncollapsedDeps); SemanticGraph ccDeps = intermCcDeps.ConvertIntermediateGraph(tokens); sentence.Set(typeof(SemanticGraphCoreAnnotations.CollapsedCCProcessedDependenciesAnnotation), ccDeps); sentences.Add(sentence); } doc.Set(typeof(CoreAnnotations.SentencesAnnotation), sentences); return(Pair.MakePair(doc, @is)); }
private IntTuple[] applyFibonacciIdentity(List<IntTuple> intTuplesOfFactors) { HashSet<IntTuple> currentIntTuples = new HashSet<IntTuple>(comparer); foreach (var intTuple in intTuplesOfFactors) { currentIntTuples = applyFibonacciIdentity(currentIntTuples, intTuple); } IntTuple[] result = new IntTuple[currentIntTuples.Count]; currentIntTuples.CopyTo(result); return result; }
private void addNumSquareForLaterNum(int limit, List<IntTuple>[] dictOfSolutions, int num) { if (num <= Math.Sqrt(limit)) { int laterNum = num * num; IntTuple tupleForLaterNum = new IntTuple() { Tuple = new int[] { 0, num } }; updateTuplesOfLaterNum(dictOfSolutions, laterNum, tupleForLaterNum); } }