krauthaufen / Adaptify

MIT License
38 stars 3 forks source link

Getting started help #35

Closed somelinguist closed 1 year ago

somelinguist commented 1 year ago

Hi. Sorry if this is the wrong place to ask this, but are there any minimal examples/templates of how to set up a project using Adaptify that 1) aren't part of this repository and 2) also don't use the Aardvark Platform? I'm trying to wrap my head around it, but I haven't used Paket or Fake, etc. very much, so I'm having trouble getting started setting up a project to try out generating adaptive types. Thanks!

krauthaufen commented 1 year ago

Hey, you can basically just add a package-reference to Adaptify.MSBuild in your project or you can use the adaptify tool (also from nuget)

With the msbuild package you only need to add a source-file with annotated types ([<ModelType>]) and the adwptive variants should properly be generated. For technical reasons the generated types will only be visible in subsequent files (after the one containing the definitions)

The tool variant is a bit more transparent but also a little more complicated.

krauthaufen commented 1 year ago

Actually using the tool is also not that hard:

  1. you install the adaptify tool via dotnet tool install
  2. You run it on your project like here
  3. You manually add the generated file to your project

That way you need to run the tool whenever you change something in your model-types.

We use this quite frequently, since the msbuild integration doesn't play well with some IDE/autocomplete things.

somelinguist commented 1 year ago

Hi. Thanks for the help. I'm still having some problems getting started.

I tried using Adaptify.MSBuild 1.1.9, and I can get the project to build, but it doesn't look like it's generating anything? Here's the output from running dotnet build:

UPDATED: I just discovered I had inadvertently deleted the [<ModelType>] attributed in my model. Now running with Adaptify.MSBuild, the Model.g.fs file is getting generated in some temp directory instead of the project directory, and I get the following warning:

The 'rec' on this module is implied by an outer 'rec' declaration and is being ignored [/Users/kevin/code/adaptive/xml/InterlinearText/InterlinearText.fsproj]

I'm still not sure if I'm doing it correctly.

More background about my build environment:

macOS 13.2.1 dotnet 7.0.100

UPDATE: this part still doesn't work I also tried running the adaptify tool (also version 1.1.9), but it gives the following error:

~/code/adaptive/xml/InterlinearText> dotnet adaptify --local --verbose --force /Users/kevin/code/adaptive/xml/Interlineartext/InterlinearText.fsproj
> version: 1.1.9.0
> CWD: /Users/kevin/code/adaptive/xml/InterlinearText
> 1 projects
> /Users/kevin/code/adaptive/xml/Interlineartext/InterlinearText.fsproj
> ERRORS in /Users/kevin/code/adaptive/xml/Interlineartext/InterlinearText.fsproj
>   Build started.
Project "InterlinearText.fsproj" (ResolveAssemblyReferencesDesignTime;ResolveProjectReferencesDesignTime;ResolvePackageDependenciesDesignTime;_GenerateCompileDependencyCache;_ComputeNonExistentFileProperty;CoreCompile target(s)):
Target "AssignProjectConfiguration" skipped, due to false condition; ('$(CurrentSolutionConfigurationContents)' != '' or '@(ProjectReference)'!='') was evaluated as ('' != '' or ''!='').
Target "ProcessFrameworkReferences" skipped, due to false condition; ('@(FrameworkReference)' != '') was evaluated as ('' != '').
Target "_NormalizeTargetPlatformVersion" skipped, due to false condition; ('$(TargetPlatformVersion)' != '' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), 5.0)) and ('$(Language)' != 'C++' or '$(_EnablePackageReferencesInVCProjects)' == 'true')) was evaluated as ('7.0' != '' and '.NETStandard' == '.NETCoreApp' and False and ('F#' != 'C++' or '' == 'true')).
Target "_CheckForLanguageAndFeatureCombinationSupport" in file "/usr/local/share/dotnet/sdk/7.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets" from project "/Users/kevin/code/adaptive/xml/Interlineartext/InterlinearText.fsproj" (target "ProcessFrameworkReferences" depends on it):
Task "NETSdkError" skipped, due to false condition; (('$(Language)' == 'C++' and '$(_EnablePackageReferencesInVCProjects)' != 'true') and $(OutputType) != 'library' and '$(TargetFrameworkIdentifier)' == '.NETCoreApp') was evaluated as (('F#' == 'C++' and '' != 'true') and Library != 'library' and '.NETStandard' == '.NETCoreApp').
Task "NETSdkError" skipped, due to false condition; (('$(Language)' == 'C++' and '$(_EnablePackageReferencesInVCProjects)' != 'true') and $(EnableComHosting) == 'true') was evaluated as (('F#' == 'C++' and '' != 'true') and  == 'true').
Task "NETSdkError" skipped, due to false condition; (('$(Language)' == 'C++' and '$(_EnablePackageReferencesInVCProjects)' != 'true') and $(SelfContained) == 'true') was evaluated as (('F#' == 'C++' and '' != 'true') and  == 'true').
Done building target "_CheckForLanguageAndFeatureCombinationSupport" in project "InterlinearText.fsproj".
Target "UpdateAspNetToFrameworkReference" skipped, due to false condition; ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And '$(_TargetFrameworkVersionWithoutV)' >= '3.0') was evaluated as ('.NETStandard' == '.NETCoreApp' And '2.0' >= '3.0').
Target "IncludeTargetingPackReference" skipped, due to false condition; ('$(TargetFrameworkMoniker)' != '' and '$(TargetFrameworkIdentifier)' == '.NETFramework' and '$(AutomaticallyUseReferenceAssemblyPackages)' == 'true') was evaluated as ('.NETStandard,Version=v2.0' != '' and '.NETStandard' == '.NETFramework' and 'true' == 'true').
Target "CheckForImplicitPackageReferenceOverrides" in file "/usr/local/share/dotnet/sdk/7.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.DefaultItems.Shared.targets" from project "/Users/kevin/code/adaptive/xml/Interlineartext/InterlinearText.fsproj" (target "ApplyImplicitVersions" depends on it):
The "CheckForImplicitPackageReferenceOverrides" task could not be loaded from the assembly /usr/local/share/dotnet/sdk/7.0.100/Sdks/Microsoft.NET.Sdk/targets/../tools/net7.0/Microsoft.NET.Build.Tasks.dll. Could not load file or assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
 Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
Done building target "CheckForImplicitPackageReferenceOverrides" in project "InterlinearText.fsproj" -- FAILED.
Done building project "InterlinearText.fsproj" -- FAILED.
Build FAILED.

Here is the project file I'm using, (with the MSBuild package commented out as I just ran the tool):

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Model.fs" />
    <Compile Include="Linq.fs" />
    <Compile Include="Serializer.fs" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="FSharp.Core" Version="5.0.0" />
    <PackageReference Include="Adaptify.Core" Version="1.1.9" />
    <!-- <PackageReference Include="Adaptify.MSBuild" Version="1.1.9">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
    </PackageReference> -->
    <PackageReference Include="FSharp.Data.Adaptive" Version="1.2.13" />
  </ItemGroup>
</Project>

I also tried using the preview release of Adaptify.MSbuild and the Adaptify tool. However, the later versions of Adaptify.MSbuild won't build, and later version of the tool won't install.

Thanks again for your help!

krauthaufen commented 1 year ago

Hey, the msbuild plugin generates files to some temp-folder and (magically) adds them to the project (you probalby won‘t see the generated file in your IDE)

so basicall when you have a MyType you should see a AdaptiveMyType in the files following the one defining MyType

I guess the tool is having problems with your project file. Is this a net7.0 project? If not you could try adding a global.json forcing dotnet 6.0 for the moment?

somelinguist commented 1 year ago

Hi again, thanks so much for the quick response.

Using global.json set to dotnet 6.0 worked. I don't actually need 7.0, so this will be just fine. I always forget I can do this. :)

somelinguist commented 1 year ago

As I'm still getting started figuring things out, I'll ask about this in this issue:

While running the tool, I got the following warning:

found model types in opaque scope

Does this indicate I've done something wrong or suboptimal with my model?

For context, my plain model is roughly something like this:

type PartA =
    {
        PKey: string
        Items: SomeSmallRecordType[]
    }

type PartB =
    {
        PKey: string
        Value: string
    }

type Part =
    | PartA of PartA
    | PartB of PartB

type Sentence =
    {
        SKey: string
        OtherData: string
        Parts: Part[]
    }

type Text =
    {
        TKey: string
        OtherData: string
        Sentences: Sentence[]
    }

My initial attempt was to mark these types with [<ModelType>]. I assume this is what generated the warning. What would be a good strategy if Sentence and Part are the primary types that change?

Thanks, and sorry for such a basic question.

somelinguist commented 1 year ago

It looks like changing Parts and Sentences to IndexLists makes the warning go away. Is that the correct way to handle things?

krauthaufen commented 1 year ago

Hey, yeah, since your sentences may change internally and the array of sentences may also change the system somehow needs to identify which sentence is which after a change. The way we did this is by using IndexList (since Index can remain stable after insertions/deletions)

somelinguist commented 1 year ago

Thanks!

krauthaufen commented 1 year ago

Just out of curiosity, what are you creating with this? We were always interested in writing some sort of adaptive parser but sadly we never found the time...

somelinguist commented 1 year ago

Hi. Thanks for asking.

I've been working on an app for annotating and searching interlinear glossed texts. It lets the user take a text in one language and add word and morpheme glosses in an analysis language. The GUI displays the whole text in a nice format, and allows the user to select a word to add/edit the gloss for it. It also offers suggested glosses for word based on its occurrence elsewhere in the corpus.

The individual texts are stored in XML files. For now, I've just been using System.XML.Linq to load the texts, map them to the view, do the updates, etc. It works alright, but as I add more features, the code gets messier.

So now I'm looking at if it would help to use FSharp.Data.Adaptive with a better model and use it to map the views of the text, keep track of updates, etc. The way the GUI works, I'm making lots of updates to nested data, and then have to update the view. Often it's just one individual part of the view, but sometimes it also involves updating suggestions for other unglossed occurrences of the word in the text, merging/splitting words in a sentence, etc. I've eventually hoping to add things like find/search as well.

The library looks promising for handling all this, but I'm still trying to get my head around it.