protected static string ReplacePattern(PatternOption option) { if (option == null) return string.Empty; var result = option.Pattern; var prefix = string.Empty; var completed = false; PatternItem item = null; do { switch (option.Type) { case TypePattern.share: case TypePattern.checkin: case TypePattern.post: var post = option.Type == TypePattern.share ? option.Share : option.Post; item = null; if (post != null) item = new PatternItem() { Type = string.IsNullOrWhiteSpace(prefix) ? GetTypePatternName(option.Type) : "{type}", Id = post.Id, TimeSpan = DateString(post.Published, DateType.TimeSpan), Date = DateString(post.Published, DateType.Date), Time = DateString(post.Published, DateType.Time), DateTime = DateString(post.Published, DateType.DateTime), ActorName = post.Actor.DisplayName, Actor = post.Actor.Id, SharePath = !string.IsNullOrWhiteSpace(option.SharePath) ? option.SharePath : "{sharepath}", PostFileName = !string.IsNullOrWhiteSpace(option.PostFileName) ? option.PostFileName : "{postfilename}", Title = !string.IsNullOrWhiteSpace(post.Title) ? ForTitle(post.Title, 100) : (string.IsNullOrWhiteSpace(post.Object.Content) ? post.Id : ForTitle(Regex.Replace(post.Object.Content, "<.*?>", "", RegexOptions.IgnoreCase | RegexOptions.Multiline), 100)) }; if (!(completed = option.Type != TypePattern.share)) { option.Type = TypePattern.post; } break; case TypePattern.comment: var comment = option.Comment; item = null; if (comment != null) item = new PatternItem() { Type = string.IsNullOrWhiteSpace(prefix) ? GetTypePatternName(option.Type) : "{type}", Id = comment.Id, TimeSpan = DateString(comment.Published, DateType.TimeSpan), Date = DateString(comment.Published, DateType.Date), Time = DateString(comment.Published, DateType.Time), DateTime = DateString(comment.Published, DateType.DateTime), ActorName = comment.Actor.DisplayName, Actor = comment.Actor.Id, SharePath = !string.IsNullOrWhiteSpace(option.SharePath) ? option.SharePath : "{sharepath}", PostFileName = !string.IsNullOrWhiteSpace(option.PostFileName) ? option.PostFileName : "{postfilename}", Title = comment.Object == null || string.IsNullOrWhiteSpace(comment.Object.Content) ? comment.Id : ForTitle(Regex.Replace(comment.Object.Content, "<.*?>", "", RegexOptions.IgnoreCase | RegexOptions.Multiline), 100) }; option.Type = TypePattern.post; break; case TypePattern.plus: case TypePattern.reshare: var person = option.Person; item = null; if (person != null) { item = new PatternItem() { Type = string.IsNullOrWhiteSpace(prefix) ? GetTypePatternName(option.Type) : "{type}", Id = person.Id, TimeSpan = DateString(DateTime.Now.ToString(), DateType.TimeSpan), Date = DateString(DateTime.Now.ToString(), DateType.Date), Time = DateString(DateTime.Now.ToString(), DateType.Time), DateTime = DateString(DateTime.Now.ToString(), DateType.DateTime), ActorName = person.DisplayName, Actor = person.Id, SharePath = !string.IsNullOrWhiteSpace(option.SharePath) ? option.SharePath : "{sharepath}", PostFileName = !string.IsNullOrWhiteSpace(option.PostFileName) ? option.PostFileName : "{postfilename}", Title = "{posttitle}" }; post = option.Post; if (post != null) { item.TimeSpan = DateString(post.Published, DateType.TimeSpan); item.Date = DateString(post.Published, DateType.Date); item.Time = DateString(post.Published, DateType.Time); item.DateTime = DateString(post.Published, DateType.DateTime); } } option.Type = TypePattern.post; break; } if (item != null && !string.IsNullOrWhiteSpace(result)) result = ApplyPattern(result, item, prefix, new string[] { "type", "sharepath", "postfilename" }); if (!completed) prefix = "post"; else break; } while (!completed); if (result == "{type}:{title}") result = "вот же хер"; return ReplaceForLog(result.Replace("//", "/")); }
internal TriplePatternObjectPart(TriplePatternBuilder triplePatternBuilder, PatternItem subjectPatternItem, PatternItem predicatePatternItem, INamespaceMapper prefixes) { _subjectPatternItem = subjectPatternItem; _predicatePatternItem = predicatePatternItem; _prefixes = prefixes; _triplePatternBuilder = triplePatternBuilder; }
protected static string ApplyPattern(string pattern, PatternItem item, string prefix = "", string[] prefixignore = null) { var result = pattern; if (string.IsNullOrWhiteSpace(result)) return string.Empty; var arr = item.GetType().GetProperties().ToArray(); foreach (var prop in arr) { result = Regex.Replace(result, MakeRule(prop.Name, prefix, prefixignore), string.Format("{0}", prop.GetValue(item, null)), RegexOptions.IgnoreCase | RegexOptions.Multiline); } return result; }
/// <summary> /// Sets a typed literal as <see cref="IMatchTriplePattern.Object"/> /// </summary> public ITriplePatternBuilder ObjectLiteral(object literal, Uri datatype) { PatternItem objectPattern = _triplePatternBuilder.PatternItemFactory.CreateLiteralNodeMatchPattern(literal, datatype); return(Object(objectPattern)); }
/// <summary> /// Sets a <see cref="PatternItem"/> as <see cref="IMatchTriplePattern.Object"/> /// </summary> public ITriplePatternBuilder Object(PatternItem objectPattern) { _triplePatternBuilder.AddPattern(new TriplePattern(_subjectPatternItem, _predicatePatternItem, objectPattern)); return(_triplePatternBuilder); }
/// <summary> /// Creates a new Arbitrary Lengh Path Operator /// </summary> /// <param name="start">Path Start</param> /// <param name="end">Path End</param> /// <param name="path">Property Path</param> public BaseArbitraryLengthPathOperator(PatternItem start, PatternItem end, ISparqlPath path) : base(start, path, end) { }
/// <summary> /// Sets a literal with language tag as <see cref="IMatchTriplePattern.Object"/> /// </summary> public ITriplePatternBuilder ObjectLiteral(object literal, string langSpec) { PatternItem objectPattern = _triplePatternBuilder.PatternItemFactory.CreateLiteralNodeMatchPattern(literal, langSpec); return(Object(objectPattern)); }
/// <summary> /// Creates a new Path Evaluation Context. /// </summary> /// <param name="context">SPARQL Evaluation Context.</param> /// <param name="end">Start point of the Path.</param> /// <param name="start">End point of the Path.</param> public PathEvaluationContext(SparqlEvaluationContext context, PatternItem start, PatternItem end) { _context = context; _start = start; _end = end; if (_start.VariableName == null && _end.VariableName == null) { _earlyAbort = true; } _start.RigorousEvaluation = true; _end.RigorousEvaluation = true; }
/// <summary> /// Creates a new Negated Property Set /// </summary> /// <param name="start">Path Start</param> /// <param name="end">Path End</param> /// <param name="properties">Negated Properties</param> public NegatedPropertySet(PatternItem start, PatternItem end, IEnumerable <Property> properties) : this(start, end, properties, false) { }
private void calculate() { if (!tbHNums.IsValid || !tbVNums.IsValid || !tbOriginX.IsValid || !tbOriginY.IsValid || !tbHEndX.IsValid || !tbHEndY.IsValid || !tbVEndX.IsValid || !tbVEndY.IsValid) { return; } if (tbHNums.Value < 1 || tbVNums.Value < 1) { return; } int total = tbHNums.Value * tbVNums.Value; if (total == 1) { return; } if (tbHEndX.Value == tbVEndX.Value && tbHEndY.Value == tbVEndY.Value) { return; } if (tbOriginX.Value == tbHEndX.Value && tbOriginY.Value == tbHEndY.Value) { if (tbVNums.Value == 1 || tbHNums.Value != 1) { return; } } if (tbOriginX.Value == tbVEndX.Value && tbOriginY.Value == tbVEndY.Value) { if (tbHNums.Value == 1 || tbVNums.Value != 1) { return; } } patternItems.Clear(); //机械坐标->系统坐标 PointD pO = this.pattern.SystemRel(tbOriginX.Value, tbOriginY.Value); PointD pH = this.pattern.SystemRel(tbHEndX.Value, tbHEndY.Value); PointD pV = this.pattern.SystemRel(tbVEndX.Value, tbVEndY.Value); double hxgap = tbHNums.Value == 1 ? 0 : (pH.X - pO.X) / (tbHNums.Value - 1); double hygap = tbHNums.Value == 1 ? 0 : (pH.Y - pO.Y) / (tbHNums.Value - 1); double vxgap = tbVNums.Value == 1 ? 0 : (pV.X - pO.X) / (tbVNums.Value - 1); double vygap = tbVNums.Value == 1 ? 0 : (pV.Y - pO.Y) / (tbVNums.Value - 1); if (tbHNums.Value == 1 || tbVNums.Value == 1) { if (tbHNums.Value == 1) { for (int j = 0; j < total; j++) { PointD p = new PointD(pO.X + j * hxgap + j * vxgap, pO.Y + j * hygap + j * vygap); PatternItem pI = new PatternItem(0, j, p, ValveType.Valve1, true); patternItems.Add(pI); } } else { for (int j = 0; j < total; j++) { PointD p = new PointD(pO.X + j * hxgap + j * vxgap, pO.Y + j * hygap + j * vygap); PatternItem pI = new PatternItem(j, 0, p, ValveType.Valve1, true); patternItems.Add(pI); } } } else { switch (stepAndRepeatCmdLine.Mode) { case RepeatMode.X向蛇行: for (int i = 0; i < tbVNums.Value; i++) { if (i % 2 == 0) { for (int j = 0; j < tbHNums.Value; j++) { PointD p = new PointD(pO.X + j * hxgap + i * vxgap, pO.Y + j * hygap + i * vygap); PatternItem pI = new PatternItem(i, j, p, ValveType.Valve1, true); patternItems.Add(pI); } } else { for (int j = tbHNums.Value - 1; j >= 0; j--) { PointD p = new PointD(pO.X + j * hxgap + i * vxgap, pO.Y + j * hygap + i * vygap); PatternItem pI = new PatternItem(i, j, p, ValveType.Valve1, true); patternItems.Add(pI); } } } break; case RepeatMode.X向之行: for (int i = 0; i < tbVNums.Value; i++) { for (int j = 0; j < tbHNums.Value; j++) { PointD p = new PointD(pO.X + j * hxgap + i * vxgap, pO.Y + j * hygap + i * vygap); PatternItem pI = new PatternItem(i, j, p, ValveType.Valve1, true); patternItems.Add(pI); } } break; case RepeatMode.Y向蛇行: for (int j = 0; j < tbHNums.Value; j++) { if (j % 2 == 0) { for (int i = 0; i < tbVNums.Value; i++) { PointD p = new PointD(pO.X + j * hxgap + i * vxgap, pO.Y + j * hygap + i * vygap); PatternItem pI = new PatternItem(i, j, p, ValveType.Valve1, true); patternItems.Add(pI); } } else { for (int i = tbVNums.Value - 1; i >= 0; i--) { PointD p = new PointD(pO.X + j * hxgap + i * vxgap, pO.Y + j * hygap + i * vygap); PatternItem pI = new PatternItem(i, j, p, ValveType.Valve1, true); patternItems.Add(pI); } } } break; case RepeatMode.Y向之行: for (int j = 0; j < tbHNums.Value; j++) { for (int i = 0; i < tbVNums.Value; i++) { PointD p = new PointD(pO.X + j * hxgap + i * vxgap, pO.Y + j * hygap + i * vygap); PatternItem pI = new PatternItem(i, j, p, ValveType.Valve1, true); patternItems.Add(pI); } } break; } } }
/// <summary> /// Constructs a Full Text Match property function /// </summary> /// <param name="info">Property Function information</param> public FullTextMatchPropertyFunction(PropertyFunctionInfo info) { if (info == null) { throw new ArgumentNullException("info"); } if (!EqualityHelper.AreUrisEqual(info.FunctionUri, this.FunctionUri)) { throw new ArgumentException("Property Function information is not valid for this function"); } //Get basic arguments this._matchVar = info.SubjectArgs[0]; if (this._matchVar.VariableName != null) { this._vars.Add(this._matchVar.VariableName); } if (info.SubjectArgs.Count == 2) { this._scoreVar = info.SubjectArgs[1]; if (this._scoreVar.VariableName != null) { this._vars.Add(this._scoreVar.VariableName); } } //Check extended arguments this._searchVar = info.ObjectArgs[0]; if (this._searchVar.VariableName != null) { this._vars.Add(this._searchVar.VariableName); } switch (info.ObjectArgs.Count) { case 1: break; case 2: PatternItem arg = info.ObjectArgs[1]; if (arg.VariableName != null) { throw new RdfQueryException("Cannot use a variable as the limit/score threshold for full text queries, must use a numeric constant"); } IValuedNode n = ((NodeMatchPattern)arg).Node.AsValuedNode(); switch (n.NumericType) { case SparqlNumericType.Integer: this._limit = (int)n.AsInteger(); break; case SparqlNumericType.Decimal: case SparqlNumericType.Double: case SparqlNumericType.Float: this._threshold = n.AsDouble(); break; default: throw new RdfQueryException("Cannot use a non-numeric constant as the limit/score threshold for full text queries, must use a numeric constant"); } break; case 3: default: PatternItem arg1 = info.ObjectArgs[1]; PatternItem arg2 = info.ObjectArgs[2]; if (arg1.VariableName != null || arg2.VariableName != null) { throw new RdfQueryException("Cannot use a variable as the limit/score threshold for full text queries, must use a numeric constant"); } IValuedNode n1 = ((NodeMatchPattern)arg1).Node.AsValuedNode(); switch (n1.NumericType) { case SparqlNumericType.NaN: throw new RdfQueryException("Cannot use a non-numeric constant as the score threshold for full text queries, must use a numeric constant"); default: this._threshold = n1.AsDouble(); break; } IValuedNode n2 = ((NodeMatchPattern)arg2).Node.AsValuedNode(); switch (n2.NumericType) { case SparqlNumericType.NaN: throw new RdfQueryException("Cannot use a non-numeric constant as the limit for full text queries, must use a numeric constant"); default: this._limit = (int)n2.AsInteger(); break; } break; } }
/// <summary> /// Creates a new Full Text Operator /// </summary> /// <param name="provider">Search Provider</param> /// <param name="algebra">Inner Algebra</param> /// <param name="matchVar">Match Variable</param> /// <param name="searchTerm">Search Term</param> /// <param name="limit">Limit</param> public BaseFullTextOperator(IFullTextSearchProvider provider, ISparqlAlgebra algebra, PatternItem matchVar, PatternItem searchTerm, int limit) : this(provider, algebra, matchVar, null, searchTerm, limit, Double.NaN) { }
/// <summary> /// Creates a new Full Text Operator /// </summary> /// <param name="provider">Search Provider</param> /// <param name="algebra">Inner Algebra</param> /// <param name="matchVar">Match Variable</param> /// <param name="scoreVar">Score Variable</param> /// <param name="searchTerm">Search Term</param> /// <param name="limit">Limit</param> /// <param name="scoreThreshold">Score Threshold</param> public BaseFullTextOperator(IFullTextSearchProvider provider, ISparqlAlgebra algebra, PatternItem matchVar, PatternItem scoreVar, PatternItem searchTerm, int limit, double scoreThreshold) { this._provider = provider; this.InnerAlgebra = algebra; this._matchVar = matchVar; this._scoreVar = scoreVar; this._searchTerm = searchTerm; this._limit = limit; this._scoreThreshold = scoreThreshold; }
/// <summary> /// Creates a new Full Text Operator /// </summary> /// <param name="provider">Search Provider</param> /// <param name="algebra">Inner Algebra</param> /// <param name="matchVar">Match Variable</param> /// <param name="searchTerm">Search Term</param> /// <param name="scoreThreshold">Score Threshold</param> public BaseFullTextOperator(IFullTextSearchProvider provider, ISparqlAlgebra algebra, PatternItem matchVar, PatternItem searchTerm, double scoreThreshold) : this(provider, algebra, matchVar, null, searchTerm, -1, scoreThreshold) { }