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

It is not clear how to use this fork in a C# application #3

Open
ccaneke opened this issue May 16, 2021 · 7 comments
Open

It is not clear how to use this fork in a C# application #3

ccaneke opened this issue May 16, 2021 · 7 comments
Assignees

Comments

@ccaneke
Copy link

ccaneke commented May 16, 2021

Since there doesn't seem to be a nuget package for this fork, it would be helpful to include a usage section in the README

@gjdv
Copy link
Owner

gjdv commented May 17, 2021

Thank you for your suggestion.
Let me just check what information you would like to see there? The steps to use it are (as with any C# code) are: 1) add the project to your solution (using the .csproj file) and 2) you can include the classes you need at the place you need it using the C# "using" statement. For example usage, see any of the test files, e.g., https://github.com/gjdv/simplenlg/blob/master/srcCsharp/Test/external/ExternalTest.cs

<Edit: corrected the mixup of solution and project>

@ccaneke
Copy link
Author

ccaneke commented May 17, 2021

@gjdv thanks for responding. I'm using visual studio code so I'm not sure:

  1. add the solution to your project (using the .sln file)

applies to me. Can you confirm whether your port of SimpleNLG works in .NET Core, or is it only for .NET Framework?

@gjdv
Copy link
Owner

gjdv commented May 17, 2021

It had been a while since I used the this code (or C# at all :) ), so I verified for you by creating a new solution and project. The code works in both frameworks (.NET Framework and .NET Core).
I realize that in the previous post I mixed up 'project' and 'solution'. (edit: corrected)

Here are the steps to take in Visual Studio:

  1. Create a new project. (this time I choose Console App (.NET Core))
  2. In the Solution Explorer (right hand side), right click on the created Solution and choose Add->Existing Project
  3. Go to the folder where you checked out the SimpleNLG C# code and select the SimpleNLG project file (in the subfolder srcCsharp)
  4. Use what you need from the package, e.g., try this in Program.cs to the following example (based on RealiserTest.cs):
using System;
using SimpleNLG.Main.features;
using SimpleNLG.Main.framework;
using SimpleNLG.Main.lexicon;
using SimpleNLG.Main.phrasespec;
using SimpleNLG.Main.realiser.english;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Lexicon lexicon = Lexicon.DefaultLexicon;
            NLGFactory nlgFactory = new NLGFactory(lexicon);
            Realiser realiser = new Realiser(lexicon);
            DocumentElement sentence1 = nlgFactory.createSentence();
            NPPhraseSpec subject_1 = nlgFactory.createNounPhrase("the", "cat");
            VPPhraseSpec verb_1 = nlgFactory.createVerbPhrase("jump");
            verb_1.setFeature(Feature.FORM, Form.PRESENT_PARTICIPLE);
            PPPhraseSpec prep_1 = nlgFactory.createPrepositionPhrase();
            NPPhraseSpec object_1 = nlgFactory.createNounPhrase();
            object_1.setDeterminer("the");
            object_1.setNoun("counter");
            prep_1.addComplement(object_1);
            prep_1.setPreposition("on");
            SPhraseSpec clause_1 = nlgFactory.createClause();
            clause_1.setSubject(subject_1);
            clause_1.VerbPhrase = verb_1;
            clause_1.setObject(prep_1);
            sentence1.addComponent(clause_1);
            NLGElement res = realiser.realise(sentence1);
            Console.WriteLine(res.Realisation);
            System.Threading.Thread.Sleep(10000); // avoid window closing before you can read the output
        }
    }
}

@gjdv gjdv self-assigned this May 17, 2021
@ccaneke
Copy link
Author

ccaneke commented May 17, 2021

@gjdv thanks for the detailed response. I have copied SimpleNLG.csproj to the console app folder but there are dependency errors. The output of cat SimpleNLG.csproj contains the following lines:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\System.Data.SQLite.Core.1.0.108.0\build\net46\System.Data.SQLite.Core.targets'))" />
  </Target>

dotnet list SimpleNLG.csproj package outputs the following error:

The project `~/consoleApp/SimpleNLG.csproj` uses package.config for NuGet packages, while the command works only with package reference projects.

It seems to me that this fork will only with Visual Studio, not Visual Studio Code, because Visual Studio Code does not use solution files.

@gjdv
Copy link
Owner

gjdv commented May 17, 2021

@ccaneke Thanks for the info. It looks like 'Package reference projects' are a new format, which I should be able to migrate to (https://docs.microsoft.com/en-us/nuget/consume-packages/migrate-packages-config-to-package-reference). I'll give it a try tomorrow

@gjdv
Copy link
Owner

gjdv commented May 18, 2021

@ccaneke I tried migrating to PackageReference, which seemed to work and led to the project file attached (and removed the packages.config file).
SimpleNLG.zip

Then I tried recreating the above test project in .NET Core and found that now I get messages that SimpleNLG is not compatible with .NET Core. Unfortunately porting it from .NET Framework to Core is far from straight forward and will take me more time than I have available right now. There seems to be an (unofficial) tool to help in the process. Perhaps you can give that a try?

@ccaneke
Copy link
Author

ccaneke commented May 25, 2021

@gjdv thanks for updating the project to use a .csproj project file instead of a package.config file. Could the reason that SimpleNLG is not compatible with .NET Core be either because the .csproj references .NET Framework instead of .NET Core, or SimpleNLG uses namespaces from .NET Framework that are not available in .NET Core?

When I get the chance I'll take a look at that try-convert dotnet tool you linked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants