/// <summary> /// アルバムの登録 /// </summary> /// <param name="albumName"></param> /// <returns>終了状態を数値で返す</returns> public int Execute(string albumName) { IEnumerable <Keyword> result = keywordRepository.Find((IQueryable <Keyword> keywords) => (from p in keywords where p.KeyText == keytext select p)); if (albumName != "") { // 登録済みのアルバム名でない場合 if (result == null || result.Count() == 0) { var keyword = Keyword.Create(keytext); keywordRepository.Store(keyword); // 正常終了 return(0); } else { // 既存のアルバム名 return(2); } } else { // アルバム名未入力 return(1); } }
public static LogicalNot Create() { var not = new LogicalNot(); not.Stack.AddLast(Keyword.Create("NOT")); return(not); }
[TestMethod] //テスト5 public void キーワードを新規登録できること() { var firstKeyword = Keyword.Create("firstKeyword"); var secondKeyword = Keyword.Create("secondKeyword"); keywordRepository.Store(firstKeyword); keywordRepository.Store(secondKeyword); } // KeywordRepository.storeのテスト完了
[TestMethod] //テスト3 public void DB上に存在する同じ名前のキーワードを作成する場合DB上のそのキーワードを返す() { var keyword = Keyword.Create("海"); var result = keywordRepository.Find(allKeyword => allKeyword.FirstOrDefault(k => k.Name == keyword.Name)); Assert.AreEqual(keyword.Name, result.Name); }
[TestMethod] //テスト4 public void キーワード新規作成時にそのキーワードがDB上に存在しない場合nullを返す() { var newkeyword = Keyword.Create("newKeyword"); var result = keywordRepository.Find(allKeyword => allKeyword.FirstOrDefault(k => k.Name == newkeyword.Name)); Assert.AreEqual(null, result); } //4番目のテストと5番目のテストでKeywordRepository.Find(Func<IQueryable<Keyword>, Keyword> query)のテスト完了
public static LogicalOperator Create(string keyword) { var lop = new LogicalOperator(); lop.Stack.AddLast(Keyword.Create(keyword)); return(lop); }
public static WhereClause Create(SearchCondition sc) { var wh = new WhereClause(); wh.Stack.AddLast(Keyword.Create("WHERE")); wh.Stack.AddLast(Whitespace.Create()); wh.Stack.AddLast(sc); return(wh); }
[TestMethod] //テスト10 public void 写真のキーワードを更新できること() { var keyword = Keyword.Create("newKeyword"); keywordRepository.Store(keyword); var changedKeyword = photoRepository.Find(allphoto => allphoto.FirstOrDefault(p => p.File.FilePath == "ChangeKeyword.bmp")); changedKeyword.IsAssignedTo(keyword); photoRepository.Store(changedKeyword); }
[TestMethod] //テスト9 public void 既存の写真にキーワードを追加できること() { var keyword = Keyword.Create("haveKeyword"); keywordRepository.Store(keyword); var haveKeyword = photoRepository.Find(allphoto => allphoto.FirstOrDefault(p => p.File.FilePath == "AddKeyword.bmp")); haveKeyword.IsAssignedTo(keyword); photoRepository.Store(haveKeyword); }
//keytextが一致するIEnumerable<Keyword>を返す public Keyword Exist(string keytext) { IEnumerable <Keyword> keywords = Find(x => { return(from keyword in x where keyword.KeyText == keytext select keyword); }); if (keywords == null) { return(Keyword.Create(keytext)); } return(keywords.First()); }
/// <summary> /// アルバムの登録 /// </summary> /// <param name="keyword"></param> /// <returns>終了状態を数値で返す</returns> public int Execute(string keywordName) { var result = _keywordRepository.Find(keywords => keywords.SingleOrDefault(keyword => keyword.Name == keywordName)); // 登録済みのアルバム名でない場合 if (result == null) { var keyword = Keyword.Create(keywordName); _keywordRepository.Store(keyword); // 正常終了 return(0); } else { // 既存のアルバム名 return(1); } }
public WhereClause GenerateWhereClauseSpecificToTable(TableReference table) { SearchCondition sc = null; // Loop over all conditions (JOIN ONs and WHERE conditions) // Result will be a combinations of the table specific conditions terms // of all these // Chain up search conditions with AND operator foreach (var condition in conditions) { foreach (var ex in EnumerateCnfTermsSpecificToTable(condition, table)) { var nsc = ex.GetParsingTree(); if (sc != null) { nsc.Stack.AddLast(Whitespace.Create()); nsc.Stack.AddLast(LogicalOperator.CreateAnd()); nsc.Stack.AddLast(Whitespace.Create()); nsc.Stack.AddLast(sc); } sc = nsc; } } // Prefix with the WHERE keyword if (sc != null) { var where = new WhereClause(); where.Stack.AddLast(Keyword.Create("WHERE")); where.Stack.AddLast(Whitespace.Create()); where.Stack.AddLast(sc); return(where); } else { return(null); } }
/// <summary> /// キーワードの登録 /// </summary> /// <param name="keytext"></param> /// <returns>終了状態を数値で返す</returns> public int Execute(string keytext) { //登録するキーワードの文字数が100文字を超えていた場合 if (keytext.Length > 100) { throw new ArgumentOutOfRangeException("入力されたkeywordの文字数が制限を超えています"); } //キーワードが入力されていない場合(初期化無しを想定) if (keytext == null) { throw new ArgumentNullException("keywordが入力されていません"); } //DBに既にキーワードが格納されているか IEnumerable <Keyword> result = keywordRepository.Find((IQueryable <Keyword> keywords) => (from p in keywords where p.KeyText == keytext select p)); if (keytext != "") { // 登録済みのキーワード名でない場合 if (result == null || result.Count() == 0) { var keyword = Keyword.Create(keytext); keywordRepository.Store(keyword); // 正常終了 return(0); } else { // 既存のアルバム名 return(2); } } else { // アルバム名未入力 return(1); } }
public static IEnumerable <Thumbnail> GetThumbnails(JsonDocument doc) { if (doc == null) { throw new NullReferenceException(); } var videos = doc.RootElement.GetProperty("videos"); var summarizedInsights = doc.RootElement.GetProperty("summarizedInsights"); var thumbnails = new List <Thumbnail>(); foreach (var video in videos.EnumerateArray()) { var insights = video.GetProperty("insights"); var allFaces = insights.GetProperty("faces").EnumerateArray(); foreach (var shot in insights.GetProperty("shots").EnumerateArray()) { foreach (var keyFrame in shot.GetProperty("keyFrames").EnumerateArray()) { var keyFrameId = keyFrame.GetProperty("id").GetInt32(); System.Diagnostics.Debug.WriteLine($"Keyframe {keyFrameId}"); var instance = keyFrame.GetProperty("instances").EnumerateArray().First(); var faces = new List <Face>(); foreach (var face in allFaces) { foreach (var appearance in face.GetProperty("instances").EnumerateArray()) { var start = TimeSpan.Parse(appearance.GetProperty("start").GetString(), CultureInfo.InvariantCulture); var end = TimeSpan.Parse(appearance.GetProperty("end").GetString(), CultureInfo.InvariantCulture); var isin = Utils.IsIn(instance, start, end); if (isin) { faces.Add(new Face(instance, face)); } } } var labels = new List <string>(); foreach (var label in summarizedInsights.GetProperty("labels").EnumerateArray()) { foreach (var labelInstance in label.GetProperty("appearances").EnumerateArray()) { var start = TimeSpan.Parse(labelInstance.GetProperty("startTime").GetString(), CultureInfo.InvariantCulture); var end = TimeSpan.Parse(labelInstance.GetProperty("endTime").GetString(), CultureInfo.InvariantCulture); var isin = Utils.IsIn(instance, start, end); if (isin) { labels.Add(label.GetProperty("name").GetString()); } } } var ocr = Utils.CreateCollection(insights, instance, "ocr", delegate(JsonElement item) { return(new Ocr { Text = item.GetProperty("text").GetString(), Confidence = item.GetProperty("confidence").GetDouble(), Language = item.GetProperty("language").GetString() }); }); var keywords = Utils.CreateCollection(insights, instance, "keywords", delegate(JsonElement item) { return(Keyword.Create(item)); }); var topics = Utils.CreateCollection(insights, instance, "topics", delegate(JsonElement item) { return(new Topic { Name = item.GetProperty("name").GetString(), Confidence = item.GetProperty("confidence").GetDouble() }); }); var sentiments = Utils.CreateCollection(insights, instance, "sentiments", delegate(JsonElement sentiment) { return(new Sentiment { SentimentType = sentiment.GetProperty("sentimentType").GetString(), AverageScore = sentiment.GetProperty("averageScore").GetDouble(), Start = Utils.GetTimeSpan(instance, "start"), End = Utils.GetTimeSpan(instance, "end") }); }); var namedLocations = Utils.CreateCollection(insights, instance, "namedLocations", delegate(JsonElement namedLocation) { return(new NamedLocation { Name = namedLocation.GetProperty("name").GetString(), ReferenceId = namedLocation.GetProperty("referenceId").GetString(), ReferenceUrl = namedLocation.GetProperty("referenceUrl").GetString(), Description = namedLocation.GetProperty("description").GetString(), Confidence = namedLocation.GetProperty("confidence").GetDouble(), IsCustom = namedLocation.GetProperty("isCustom").GetBoolean(), }); }); //string storageAccountName = ""; //string container = ""; var thumbnailId = instance.GetProperty("thumbnailId").GetString(); thumbnails.Add(new Thumbnail { Id = thumbnailId, //Uri will be added after this step, Video = Utils.CreateVideo(video), Start = Utils.GetTimeSpan(instance, "start"), End = Utils.GetTimeSpan(instance, "end"), Faces = faces, Labels = labels, Ocr = ocr?.ToList(), Keywords = keywords?.ToList(), Topics = topics?.ToList(), ShotTags = Utils.GetTags(shot), Playlist = Utils.CreatePlaylist(doc.RootElement), Sentiments = sentiments?.ToList(), NamedLocations = namedLocations?.ToList() }); } } } return(thumbnails); }
public IEnumerable <Scene> GetScenes(JsonDocument doc) { if (doc == null) { throw new NullReferenceException(); } var videos = doc.RootElement.GetProperty("videos"); var video = videos.EnumerateArray().FirstOrDefault(); var videoId = video.GetProperty("id").GetString(); var insights = video.GetProperty("insights"); var scenes = new List <Scene>(); foreach (var scene in insights.GetProperty("scenes").EnumerateArray()) { var sceneId = scene.GetProperty("id").GetUInt32(); var instance = scene.GetProperty("instances").EnumerateArray().First(); var start = TimeSpan.Parse(instance.GetProperty("start").GetString(), CultureInfo.InvariantCulture); var end = TimeSpan.Parse(instance.GetProperty("end").GetString(), CultureInfo.InvariantCulture); var shots = new List <Shot>(); foreach (var shot in insights.GetProperty("shots").EnumerateArray()) { var shotInstance = shot.GetProperty("instances").EnumerateArray().First(); var keyframes = new List <KeyFrame>(); foreach (var keyFrame in shot.GetProperty("keyFrames").EnumerateArray()) { var keyFrameInstance = keyFrame.GetProperty("instances").EnumerateArray().First(); var keyFrameStart = TimeSpan.Parse(keyFrameInstance.GetProperty("start").GetString(), CultureInfo.InvariantCulture); var keyFrameEnd = TimeSpan.Parse(keyFrameInstance.GetProperty("end").GetString(), CultureInfo.InvariantCulture); keyframes.Add(new KeyFrame { Id = keyFrame.GetProperty("id").GetInt32(), ThumbnailId = keyFrameInstance.GetProperty("thumbnailId").GetString(), Start = keyFrameStart.TotalSeconds, End = keyFrameEnd.TotalSeconds }); } var isin = Utils.IsIn(shotInstance, start, end); var hasTags = shot.TryGetProperty("tags", out JsonElement tags) && isin; var tagList = new List <string>(); if (hasTags) { foreach (var tag in shot.GetProperty("tags").EnumerateArray()) { tagList.Add(tag.GetString()); } } shots.Add(new Shot { Id = shot.GetProperty("id").GetInt32(), Start = Utils.GetTimeSpan(shotInstance, "start"), End = Utils.GetTimeSpan(shotInstance, "end"), Tags = hasTags ? tagList : null, KeyFrames = keyframes }); } var transcript = Utils.GetCollection(insights, "transcript", start, end, delegate(JsonElement transcriptInstance, JsonElement item) { return(new Transcript { Id = item.GetProperty("id").GetInt32(), Text = item.GetProperty("text").GetString(), Confidence = item.GetProperty("confidence").GetDouble(), SpeakerId = item.GetProperty("speakerId").GetInt32(), Language = item.GetProperty("language").GetString(), Start = Utils.GetTimeSpan(transcriptInstance, "start"), End = Utils.GetTimeSpan(transcriptInstance, "end") }); }); var faces = Utils.GetCollection(insights, "faces", start, end, delegate(JsonElement faceInstance, JsonElement face) { return(new Face(faceInstance, face)); }); var emotions = Utils.GetCollection(insights, "emotions", start, end, delegate(JsonElement element, JsonElement parent) { return(new Emotion { Id = parent.GetProperty("id").GetInt32(), Type = parent.GetProperty("type").GetString(), Start = Utils.GetTimeSpan(element, "start"), End = Utils.GetTimeSpan(element, "end") }); }); var labels = Utils.GetCollection(insights, "labels", start, end, delegate(JsonElement element, JsonElement parent) { string referenceId = null; if (parent.TryGetProperty("referenceId", out JsonElement value)) { referenceId = value.GetString(); } return(new Label { Id = parent.GetProperty("id").GetInt32(), Name = parent.GetProperty("name").GetString(), Start = Utils.GetTimeSpan(element, "start"), End = Utils.GetTimeSpan(element, "end"), Confidence = element.GetProperty("confidence").GetDouble(), ReferenceId = referenceId, Language = parent.GetProperty("language").GetString() }); }); var audioEffects = Utils.GetCollection(insights, "audioEffects", start, end, delegate(JsonElement instance, JsonElement effect) { return(new AudioEffect { Type = effect.GetProperty("type").GetString(), Start = Utils.GetTimeSpan(instance, "start"), End = Utils.GetTimeSpan(instance, "end") }); }); var sentiments = Utils.GetCollection(insights, "sentiments", start, end, delegate(JsonElement instance, JsonElement sentiment) { return(new Sentiment { SentimentType = sentiment.GetProperty("sentimentType").GetString(), AverageScore = sentiment.GetProperty("averageScore").GetDouble(), Start = Utils.GetTimeSpan(instance, "start"), End = Utils.GetTimeSpan(instance, "end") }); }); var keywords = Utils.GetCollection(insights, "keywords", start, end, delegate(JsonElement instance, JsonElement keyword) { return(Keyword.Create(keyword)); }); var namedLocations = Utils.GetCollection(insights, "namedLocations", start, end, delegate(JsonElement instance, JsonElement namedLocation) { return(new NamedLocation { Name = namedLocation.GetProperty("name").GetString(), ReferenceId = namedLocation.GetProperty("referenceId").GetString(), ReferenceUrl = namedLocation.GetProperty("referenceUrl").GetString(), Description = namedLocation.GetProperty("description").GetString(), Confidence = namedLocation.GetProperty("confidence").GetDouble(), IsCustom = namedLocation.GetProperty("isCustom").GetBoolean(), }); }); var contentModeration = Utils.GetCollection(insights, "visualContentModeration", start, end, delegate(JsonElement instance, JsonElement c) { return(new VisualContentModeration { Id = c.GetProperty("id").GetInt32(), AdultScore = c.GetProperty("adultScore").GetDouble(), RacyScore = c.GetProperty("racyScore").GetDouble() }); }); scenes.Add(new Scene { Id = $"{videoId}_{sceneId}", Start = start.TotalSeconds, End = end.TotalSeconds, Shots = shots?.ToList(), Video = Utils.CreateVideo(video), Transcript = transcript?.ToList(), Faces = faces?.ToList(), Emotions = emotions?.ToList(), Labels = labels?.ToList(), AudioEffects = audioEffects?.ToList(), Sentiments = sentiments?.ToList(), Playlist = Utils.CreatePlaylist(doc.RootElement), Keywords = keywords?.ToList(), NamedLocations = namedLocations?.ToList(), VisualContentModerations = contentModeration?.ToList() }); } return(scenes); }
public static IEnumerable <Thumbnail> GetThumbnails(JsonDocument doc) { if (doc == null) { throw new NullReferenceException(); } var videos = doc.RootElement.GetProperty("videos"); var summarizedInsights = doc.RootElement.GetProperty("summarizedInsights"); var thumbnails = new List <Thumbnail>(); foreach (var video in videos.EnumerateArray()) { var insights = video.GetProperty("insights"); var allFaces = insights.GetProperty("faces").EnumerateArray(); foreach (var shot in insights.GetProperty("shots").EnumerateArray()) { foreach (var keyFrame in shot.GetProperty("keyFrames").EnumerateArray()) { var instance = keyFrame.GetProperty("instances").EnumerateArray().First(); var faces = new List <Face>(); foreach (var face in allFaces) { foreach (var appearance in face.GetProperty("instances").EnumerateArray()) { var start = TimeSpan.Parse(appearance.GetProperty("start").GetString(), CultureInfo.InvariantCulture); var end = TimeSpan.Parse(appearance.GetProperty("end").GetString(), CultureInfo.InvariantCulture); var isin = Utils.IsIn(instance, start, end); if (isin) { faces.Add(new Face(instance, face)); } } } var labels = new List <string>(); foreach (var label in summarizedInsights.GetProperty("labels").EnumerateArray()) { foreach (var labelInstance in label.GetProperty("appearances").EnumerateArray()) { var start = TimeSpan.Parse(labelInstance.GetProperty("startTime").GetString(), CultureInfo.InvariantCulture); var end = TimeSpan.Parse(labelInstance.GetProperty("endTime").GetString(), CultureInfo.InvariantCulture); var isin = Utils.IsIn(instance, start, end); if (isin) { labels.Add(label.GetProperty("name").GetString()); } } } var ocr = Utils.CreateCollection(insights, instance, "ocr", delegate(JsonElement item) { return(new Ocr { Text = item.GetProperty("text").GetString(), Confidence = item.GetProperty("confidence").GetDouble(), Language = item.GetProperty("language").GetString() }); }); var keywords = Utils.CreateCollection(insights, instance, "keywords", delegate(JsonElement item) { return(Keyword.Create(item)); }); var topics = Utils.CreateCollection(insights, instance, "topics", delegate(JsonElement item) { return(new Topic { Name = item.GetProperty("name").GetString(), Confidence = item.GetProperty("confidence").GetDouble() }); }); var sentiments = Utils.CreateCollection(insights, instance, "sentiments", delegate(JsonElement sentiment) { return(new Sentiment { SentimentType = sentiment.GetProperty("sentimentType").GetString(), AverageScore = sentiment.GetProperty("averageScore").GetDouble(), Start = Utils.GetTimeSpan(instance, "start"), End = Utils.GetTimeSpan(instance, "end") }); }); thumbnails.Add(new Thumbnail { Id = instance.GetProperty("thumbnailId").GetString(), Video = Utils.CreateVideo(video), Start = Utils.GetTimeSpan(instance, "start"), End = Utils.GetTimeSpan(instance, "end"), Faces = faces, Labels = labels, Ocr = ocr?.ToList(), Keywords = keywords?.ToList(), Topics = topics?.ToList(), ShotTags = Utils.GetTags(shot), Playlist = Utils.CreatePlaylist(doc.RootElement), Sentiments = sentiments?.ToList() }); } } } return(thumbnails); }