Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype/canvas mapping #93

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/CanvasPaintings/CanvasPaintings.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.8.34316.72
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mapper", "Mapper\Mapper.csproj", "{0CC956B6-71A8-4F1E-9523-E635CCE5EAD6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Demo", "Demo\Demo.csproj", "{2D31098F-B19B-4EE0-AE3F-106A73D61147}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IIIF", "..\..\..\..\digirati-co-uk\iiif-net\src\IIIF\IIIF\IIIF.csproj", "{83E719F3-C797-43A4-B191-48D9536962E1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0CC956B6-71A8-4F1E-9523-E635CCE5EAD6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0CC956B6-71A8-4F1E-9523-E635CCE5EAD6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0CC956B6-71A8-4F1E-9523-E635CCE5EAD6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0CC956B6-71A8-4F1E-9523-E635CCE5EAD6}.Release|Any CPU.Build.0 = Release|Any CPU
{2D31098F-B19B-4EE0-AE3F-106A73D61147}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D31098F-B19B-4EE0-AE3F-106A73D61147}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D31098F-B19B-4EE0-AE3F-106A73D61147}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D31098F-B19B-4EE0-AE3F-106A73D61147}.Release|Any CPU.Build.0 = Release|Any CPU
{83E719F3-C797-43A4-B191-48D9536962E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83E719F3-C797-43A4-B191-48D9536962E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83E719F3-C797-43A4-B191-48D9536962E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83E719F3-C797-43A4-B191-48D9536962E1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {2095B719-DBE7-42FD-AC13-9E57B93488DD}
EndGlobalSection
EndGlobal
19 changes: 19 additions & 0 deletions src/CanvasPaintings/Demo/Demo.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ToMarkdownTable" Version="0.2.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\..\digirati-co-uk\iiif-net\src\IIIF\IIIF\IIIF.csproj" />
<ProjectReference Include="..\Mapper\Mapper.csproj" />
</ItemGroup>

</Project>
127 changes: 127 additions & 0 deletions src/CanvasPaintings/Demo/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@

using Demo;
using IIIF.Presentation.V3;
using IIIF.Presentation.V3.Strings;
using IIIF.Serialisation;
using Mapper;
using Mapper.DlcsApi;
using System.Text;
using System.Text.Json;

if (args.Length == 0)
{
Console.WriteLine("Supply Manifest file path or URL as arg");
return;
}

var sb = new StringBuilder();

if (args[0] == "cookbook")
{
sb.AppendAndWriteLine("# Cookbook recipes");
sb.AppendAndWriteLine();

var httpClient = new HttpClient();
var theseusColl = await httpClient.GetStringAsync("https://theseus-viewer.netlify.app/cookbook-collection.json");
var coll = theseusColl.FromJson<Collection>();
var skip = new List<string>
{
"https://iiif.io/api/cookbook/recipe/0219-using-caption-file/manifest.json"
};

AddSomeExtrasToCookbook(coll);
foreach (var item in coll.Items ?? [])
{
if(item is Manifest manifest)
{
if(skip.Contains(manifest.Id!))
{
continue;
}
sb.AppendAndWriteLine();
sb.AppendAndWriteLine("## " + manifest.Label!["en"][0].TrimStart('✅').TrimStart(' '));
sb.AppendAndWriteLine(manifest.Id);
sb.AppendAndWriteLine();
var s = await httpClient.GetStringAsync(manifest.Id);
ParseManifest(s, sb);
sb.AppendAndWriteLine();
}
}
File.WriteAllText("..\\.\\..\\..\\output.md", sb.ToString());
return;
}


if (args[0].StartsWith("http"))
{
var httpClient = new HttpClient();
sb.AppendAndWriteLine("Fetching Manifest JSON from " + args[0]);
var s = await httpClient.GetStringAsync(args[0]);
ParseManifest(s, sb);
}
else
{
sb.AppendAndWriteLine("Loading Manifest JSON from " + args[0]);
var s = File.ReadAllText(args[0]);
ParseManifest(s, sb);
}


static void ParseManifest(string manifestJson, StringBuilder sb)
{
var parser = new Parser();
var manifest = manifestJson.FromJson<Manifest>();
TweakForTesting(manifest);
var entities = parser.ParseManifest(manifest);
sb.AppendAndWriteLine();
sb.AppendAndWriteLine("### canvas_painting rows");
sb.AppendAndWriteLine();
sb.AppendAndWriteLine(entities.ToMarkdownTable());
sb.AppendAndWriteLine();
sb.AppendAndWriteLine();

var pseudoManifest = new PseudoManifest
{
Id = "https://dlc.services/iiif/99/manifests/" + entities[0].ManifestId,
PaintedResources = parser.GetPaintedResources(entities)
};
var json = JsonSerializer.Serialize(pseudoManifest,
new JsonSerializerOptions()
{
WriteIndented = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = System.Text.Json.Serialization.JsonIgnoreCondition.WhenWritingNull
});
sb.AppendAndWriteLine("### paintedResources property in DLCS Manifest");
sb.AppendAndWriteLine();
sb.AppendAndWriteLine("```json");
sb.AppendAndWriteLine(json);
sb.AppendAndWriteLine("```");
sb.AppendAndWriteLine();
sb.AppendAndWriteLine();
}

static void TweakForTesting(Manifest? manifest)
{
if (manifest!.Id == "https://iiif.io/api/cookbook/recipe/0434-choice-av/manifest.json")
{
// add a label to the Canvas to test CanvasLabel
manifest.Items![0].Label = LangMap("Pick one of these formats");
}
if(manifest!.Id == "https://iiif.io/api/cookbook/recipe/0040-image-rotation-service/manifest-service.json")
{
manifest.Id = manifest.Id.TrimEnd();
}
}


void AddSomeExtrasToCookbook(Collection coll)
{
// coll.Items!.Add(new Manifest { Id = "https://iiif.wellcomecollection.org/presentation/b18035723", Label = LangMap("Wunder external") });
coll.Items!.Add(new Manifest { Id = "https://dlcs.io/iiif-resource/wellcome/preview/5/b18035723", Label = LangMap("Wunder internal") });
}

static LanguageMap LangMap(string s)
{
return new LanguageMap("en", s);
}
8 changes: 8 additions & 0 deletions src/CanvasPaintings/Demo/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"profiles": {
"Demo": {
"commandName": "Project",
"commandLineArgs": "cookbook"
}
}
}
21 changes: 21 additions & 0 deletions src/CanvasPaintings/Demo/StringBufferX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Text;

namespace Demo
{
internal static class StringBuilderX
{
public static void AppendAndWriteLine(this StringBuilder sb, string? s = null)
{
if(string.IsNullOrWhiteSpace(s))
{
sb.AppendLine();
Console.WriteLine();
}
else
{
sb.AppendLine(s);
Console.WriteLine(s);
}
}
}
}
1 change: 1 addition & 0 deletions src/CanvasPaintings/Demo/examples.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://dlcs.io/iiif-resource/wellcome/preview/5/b18035723
Loading
Loading