-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from vitrivr/feature/segment-metadata
Refactored metadata retrieval and implemented segment metadata retrieval
- Loading branch information
Showing
11 changed files
with
258 additions
and
141 deletions.
There are no files selected for viewing
195 changes: 80 additions & 115 deletions
195
Runtime/Vitrivr/UnityInterface/CineastApi/Model/Data/MetadataStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,81 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Org.Vitrivr.CineastApi.Model; | ||
using UnityEngine; | ||
|
||
namespace Vitrivr.UnityInterface.CineastApi.Model.Data | ||
{ | ||
/// <summary> | ||
/// Access and local representation of metadata | ||
/// </summary> | ||
[Serializable] | ||
public class MetadataStore | ||
{ | ||
public MetadataStore(string id) | ||
{ | ||
ObjectId = id; | ||
Initialized = false; | ||
} | ||
|
||
/// <summary> | ||
/// Actual internal storage of metadata | ||
/// </summary> | ||
private Dictionary<string, Dictionary<string, string>> _storage = | ||
new Dictionary<string, Dictionary<string, string>>(); | ||
|
||
public string ObjectId { get; private set; } | ||
|
||
public bool Initialized { get; private set; } | ||
|
||
public void Initialize(MediaObjectMetadataQueryResult data) | ||
{ | ||
if (Initialized) | ||
{ | ||
Debug.LogWarning("Attempt to init already init'ed metadata container using cache data"); | ||
return; | ||
} | ||
|
||
foreach (var meta in data.Content.Where(meta => meta.ObjectId == ObjectId)) | ||
{ | ||
if (!DomainExists(meta.Domain)) | ||
{ | ||
_storage.Add(meta.Domain, new Dictionary<string, string>()); | ||
} | ||
|
||
var domain = _storage[meta.Domain]; | ||
domain.Add(meta.Key, meta.Value); | ||
} | ||
|
||
Initialized = true; | ||
} | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
if (Initialized) | ||
{ | ||
Debug.LogWarning($"Attempted to initialize already initialized metadata for media object {ObjectId}!"); | ||
return; | ||
} | ||
|
||
var metadataResult = await CineastWrapper.MetadataApi.FindMetaByIdAsync(ObjectId); | ||
if (!Initialized) | ||
{ | ||
Initialize(metadataResult); | ||
} | ||
} | ||
|
||
public async Task<Dictionary<string, Dictionary<string, string>>> GetAll() | ||
{ | ||
if (!Initialized) | ||
{ | ||
await InitializeAsync(); | ||
} | ||
|
||
return _storage; | ||
} | ||
|
||
public bool DomainExists(string domain) | ||
{ | ||
return _storage.ContainsKey(domain); | ||
} | ||
|
||
public string Get(string domain, string key) | ||
{ | ||
return _storage[domain][key]; | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves a metadata value using the DOMAIN.KEY notation | ||
/// </summary> | ||
/// <param name="str"></param> | ||
/// <returns></returns> | ||
public string Get(string str) | ||
{ | ||
var domainAndKey = str.Split('.'); | ||
if (domainAndKey.Length >= 1) | ||
{ | ||
return _storage[domainAndKey[0]][domainAndKey[1]]; | ||
} | ||
|
||
throw new ArgumentException("Cannot retrieve without domain"); | ||
} | ||
|
||
public List<(string Key, string Value)> GetDomain(string domain) | ||
{ | ||
var items = _storage[domain]; | ||
return items.Keys.Select(key => (key, items[key])).ToList(); | ||
} | ||
|
||
public bool Exists(string domain, string key) | ||
{ | ||
return DomainExists(domain) && _storage[domain].ContainsKey(key); | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using UnityEngine.Assertions; | ||
|
||
namespace Vitrivr.UnityInterface.CineastApi.Model.Data | ||
{ | ||
[Serializable] | ||
public abstract class MetadataStore | ||
{ | ||
/// <summary> | ||
/// Actual internal storage of metadata | ||
/// </summary> | ||
protected Dictionary<string, Dictionary<string, string>> Storage = | ||
new Dictionary<string, Dictionary<string, string>>(); | ||
|
||
public bool Initialized { get; protected set; } | ||
|
||
public abstract Task InitializeAsync(); | ||
|
||
public async Task<Dictionary<string, Dictionary<string, string>>> GetAll() | ||
{ | ||
if (!Initialized) | ||
{ | ||
await InitializeAsync(); | ||
} | ||
|
||
return Storage; | ||
} | ||
|
||
public bool DomainExists(string domain) | ||
{ | ||
Assert.IsTrue(Initialized); | ||
return Storage.ContainsKey(domain); | ||
} | ||
|
||
public string Get(string domain, string key) | ||
{ | ||
Assert.IsTrue(Initialized); | ||
return Storage[domain][key]; | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves a metadata value using the DOMAIN.KEY notation. | ||
/// Requires metadata to be initialized. | ||
/// </summary> | ||
public string Get(string str) | ||
{ | ||
Assert.IsTrue(Initialized); | ||
var domainAndKey = str.Split('.'); | ||
if (domainAndKey.Length >= 1) | ||
{ | ||
return Storage[domainAndKey[0]][domainAndKey[1]]; | ||
} | ||
|
||
throw new ArgumentException("Cannot retrieve without domain"); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves all metadata of a specific domain. | ||
/// Requires metadata to be initialized. | ||
/// </summary> | ||
public List<(string Key, string Value)> GetDomain(string domain) | ||
{ | ||
Assert.IsTrue(Initialized); | ||
var items = Storage[domain]; | ||
return items.Keys.Select(key => (key, items[key])).ToList(); | ||
} | ||
|
||
/// <summary> | ||
/// Checks if a domain key pair exists in the metadata. | ||
/// Requires metadata to be initialized. | ||
/// </summary> | ||
public bool Exists(string domain, string key) | ||
{ | ||
Assert.IsTrue(Initialized); | ||
return DomainExists(domain) && Storage[domain].ContainsKey(key); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
Runtime/Vitrivr/UnityInterface/CineastApi/Model/Data/MetadataStore.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
Runtime/Vitrivr/UnityInterface/CineastApi/Model/Data/ObjectMetadataStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Org.Vitrivr.CineastApi.Model; | ||
using UnityEngine; | ||
|
||
namespace Vitrivr.UnityInterface.CineastApi.Model.Data | ||
{ | ||
/// <summary> | ||
/// Access and local representation of metadata | ||
/// </summary> | ||
[Serializable] | ||
public class ObjectMetadataStore : MetadataStore | ||
{ | ||
public ObjectMetadataStore(string id) | ||
{ | ||
ObjectId = id; | ||
Initialized = false; | ||
} | ||
|
||
public string ObjectId { get; private set; } | ||
|
||
public void Initialize(MediaObjectMetadataQueryResult data) | ||
{ | ||
if (Initialized) | ||
{ | ||
Debug.LogWarning("Attempt to init already init'ed metadata container using cache data"); | ||
return; | ||
} | ||
|
||
foreach (var meta in data.Content.Where(meta => meta.ObjectId == ObjectId)) | ||
{ | ||
if (!Storage.ContainsKey(meta.Domain)) | ||
{ | ||
Storage.Add(meta.Domain, new Dictionary<string, string>()); | ||
} | ||
|
||
var domain = Storage[meta.Domain]; | ||
domain.Add(meta.Key, meta.Value); | ||
} | ||
|
||
Initialized = true; | ||
} | ||
|
||
public override async Task InitializeAsync() | ||
{ | ||
if (Initialized) | ||
{ | ||
Debug.LogWarning($"Attempted to initialize already initialized metadata for media object {ObjectId}!"); | ||
return; | ||
} | ||
|
||
var metadataResult = await CineastWrapper.MetadataApi.FindMetaByIdAsync(ObjectId); | ||
if (!Initialized) | ||
{ | ||
Initialize(metadataResult); | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Runtime/Vitrivr/UnityInterface/CineastApi/Model/Data/ObjectMetadataStore.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.