diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5a3497a --- /dev/null +++ b/.gitattributes @@ -0,0 +1,33 @@ +############################################################################### +# Set default behavior to automatically normalize line endings. +############################################################################### +* text=auto + +############################################################################### +# Set the merge driver for project and solution files +# +# Merging from the command prompt will add diff markers to the files if there +# are conflicts (Merging from VS is not affected by the settings below, in VS +# the diff markers are never inserted). Diff markers may cause the following +# file extensions to fail to load in VS. An alternative would be to treat +# these files as binary and thus will always conflict and require user +# intervention with every merge. +############################################################################### + +*.sln text eol=crlf +*.csproj text eol=crlf +*.vbproj text eol=crlf +*.vcxproj text eol=crlf +*.vcproj text eol=crlf +*.dbproj text eol=crlf +*.fsproj text eol=crlf +*.lsproj text eol=crlf +*.wixproj text eol=crlf +*.modelproj text eol=crlf +*.sqlproj text eol=crlf +*.wmaproj text eol=crlf + +*.xproj text eol=crlf +*.props text eol=crlf +*.filters text eol=crlf +*.vcxitems text eol=crlf diff --git a/.gitignore b/.gitignore index 2e41f69..8e64fa0 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,361 @@ examples/.idea/vcs.xml examples/.idea/workspace.xml examples/*/out -**/.DS_Store \ No newline at end of file +**/.DS_Store + +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET Core +project.lock.json +project.fragment.lock.json +artifacts/ + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*[.json, .xml, .info] + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# DotNet Sample specific files +Ontologies.g.cs diff --git a/build.gradle b/build.gradle index 089146f..235bdac 100644 --- a/build.gradle +++ b/build.gradle @@ -1,15 +1,16 @@ apply plugin: 'java' task wrapper(type: Wrapper) { - gradleVersion = '2.2' + gradleVersion = '4.10' } ext { stardogVersion = project.hasProperty("stardogVersion") ? project.getProperty("stardogVersion") : '7.0.2' - projectVersion = '0.0.5' + projectVersion = '0.0.6' distPath = "${projectDir}/dist" stardogRepo = project.hasProperty("stardogRepo") ? project.getProperty("stardogRepo") : "http://maven.stardog.com" + stardogLib = project.hasProperty("stardogLib") ? project.getProperty("stardogLib") : "." } allprojects { diff --git a/examples/dotnet/README.md b/examples/dotnet/README.md new file mode 100644 index 0000000..e952038 --- /dev/null +++ b/examples/dotnet/README.md @@ -0,0 +1,13 @@ +# Stardog .NET Examples + +The example project demonstrates how to connect to a Stardog server using [TrinityRDF](https://trinity-rdf.net/) and execute queries using SPARQL and LINQ. + +TrinityRDF provides an object mapper layer similar to Entity Framework for RDF data. The ontologies the sample uses can be found in the solution's `Ontologies/` folder. Trinity RDF discovers the ontologies in the solution's `ontologies.config` file. TrinityRDF uses the ontologies to generate mapping code - `Ontologies/Ontologies.g.cs`. A developer uses this generated code to create object models (see the files under the solution's `ObjectModels/` folder) with annotations that connect the C# object to the RDF data. These object models then allow .NET developers to create powerful applications without the need to learn SPARQL! + +## Prerequisites +* Stardog with a database named "music" populated the data from `./examples/dotnet/TrinityConsoleSample/Ontologies/music_schema.ttl` and [`music.ttl.gz`](https://github.com/stardog-union/stardog-tutorials/blob/master/music/music.ttl.gz) in a named graph called `http://stardog.com/tutorial` +* C# development environment (e.g., Visual Studio Community, Visual Studio for Mac, Visual Studio Code, .NET Core SDK, etc.) + +## Running the sample + +Build the solution and then run the resulting program. The program will connect to Stardog and run several queries and print the results to STDOUT. \ No newline at end of file diff --git a/examples/dotnet/StardogDotNetSamples.sln b/examples/dotnet/StardogDotNetSamples.sln new file mode 100644 index 0000000..181b6bf --- /dev/null +++ b/examples/dotnet/StardogDotNetSamples.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2881138B-762A-484D-966C-8C38F64B0212}" + ProjectSection(SolutionItems) = preProject + README.md = README.md + EndProjectSection +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TrinityConsoleSample", "TrinityConsoleSample\TrinityConsoleSample.csproj", "{5C32FFE3-D22E-4829-AF93-72AD4CE0C2F8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {5C32FFE3-D22E-4829-AF93-72AD4CE0C2F8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5C32FFE3-D22E-4829-AF93-72AD4CE0C2F8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5C32FFE3-D22E-4829-AF93-72AD4CE0C2F8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5C32FFE3-D22E-4829-AF93-72AD4CE0C2F8}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/examples/dotnet/TrinityConsoleSample/ObjectModels/Album.cs b/examples/dotnet/TrinityConsoleSample/ObjectModels/Album.cs new file mode 100644 index 0000000..9616d4b --- /dev/null +++ b/examples/dotnet/TrinityConsoleSample/ObjectModels/Album.cs @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2010 - 2019, Stardog Union. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using example; +using Semiodesk.Trinity; +using System; +using System.Collections.Generic; + +namespace TrinityConsoleSample.ObjectModels +{ + /// + /// A collection of songs released by an artist on physical or digital medium. + /// + [RdfClass(MUSIC.Album)] + public class Album : Resource + { + + #region Members + + /// + /// The name of an entity. + /// + [RdfProperty(MUSIC.name)] + public string Name { get; set; } + + /// + /// The release date of an album. + /// + [RdfProperty(MUSIC.date)] + public DateTime ReleaseDate { get; set; } + + /// + /// The artist that performed this album. + /// + [RdfProperty(MUSIC.artist)] + public Artist Artist { get; set; } + + /// + /// A song included in an album. + /// + [RdfProperty(MUSIC.track)] + public List Tracks { get; set; } + + #endregion + + #region Constructors + + public Album(Uri uri) : base(uri) { } + + #endregion + } +} diff --git a/examples/dotnet/TrinityConsoleSample/ObjectModels/Artist.cs b/examples/dotnet/TrinityConsoleSample/ObjectModels/Artist.cs new file mode 100644 index 0000000..719153c --- /dev/null +++ b/examples/dotnet/TrinityConsoleSample/ObjectModels/Artist.cs @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2010 - 2019, Stardog Union. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using example; +using Semiodesk.Trinity; +using System; + +namespace TrinityConsoleSample.ObjectModels +{ + /// + /// A person or a group of people creating and performing music + /// + [RdfClass(MUSIC.Artist)] + public class Artist : Resource, IArtist + { + + #region Members + + /// + /// The name of an entity. + /// + [RdfProperty(MUSIC.name)] + public string Name { get; set; } + + #endregion + + #region Constructors + + public Artist(Uri uri) : base(uri) { } + + #endregion + } +} \ No newline at end of file diff --git a/examples/dotnet/TrinityConsoleSample/ObjectModels/Band.cs b/examples/dotnet/TrinityConsoleSample/ObjectModels/Band.cs new file mode 100644 index 0000000..585ea2e --- /dev/null +++ b/examples/dotnet/TrinityConsoleSample/ObjectModels/Band.cs @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2010 - 2019, Stardog Union. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using example; +using Semiodesk.Trinity; +using System; +using System.Collections.Generic; + +namespace TrinityConsoleSample.ObjectModels +{ + /// + /// A music group; that is, is a group of people creating and performing music together. + /// + [RdfClass(MUSIC.Band)] + class Band : Artist + { + #region Members + + /// + /// A member of a band. Does not distinguish between past vs current members + /// + [RdfProperty(MUSIC.member)] + public List Members { get; set; } + + #endregion + + #region Constructors + + public Band(Uri uri) : base(uri) { } + + #endregion + + } +} \ No newline at end of file diff --git a/examples/dotnet/TrinityConsoleSample/ObjectModels/IArtist.cs b/examples/dotnet/TrinityConsoleSample/ObjectModels/IArtist.cs new file mode 100644 index 0000000..fa6af52 --- /dev/null +++ b/examples/dotnet/TrinityConsoleSample/ObjectModels/IArtist.cs @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2010 - 2019, Stardog Union. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using example; +using Semiodesk.Trinity; + +namespace TrinityConsoleSample.ObjectModels +{ + public interface IArtist + { + #region Members + + /// + /// The name of an entity. + /// + string Name { get; set; } + + #endregion + } +} diff --git a/examples/dotnet/TrinityConsoleSample/ObjectModels/Person.cs b/examples/dotnet/TrinityConsoleSample/ObjectModels/Person.cs new file mode 100644 index 0000000..161d46b --- /dev/null +++ b/examples/dotnet/TrinityConsoleSample/ObjectModels/Person.cs @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2010 - 2019, Stardog Union. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using example; +using Semiodesk.Trinity; +using System; + +namespace TrinityConsoleSample.ObjectModels +{ + /// + /// A person. + /// + [RdfClass(MUSIC.Person)] + public class Person : Resource + { + #region Members + + /// + /// The name of an entity. + /// + [RdfProperty(MUSIC.name)] + public string Name { get; set; } + + #endregion + + #region Constructors + + public Person(Uri uri) : base(uri) { } + + #endregion + } +} diff --git a/examples/dotnet/TrinityConsoleSample/ObjectModels/SoloArtist.cs b/examples/dotnet/TrinityConsoleSample/ObjectModels/SoloArtist.cs new file mode 100644 index 0000000..b7aea5a --- /dev/null +++ b/examples/dotnet/TrinityConsoleSample/ObjectModels/SoloArtist.cs @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2010 - 2019, Stardog Union. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using example; +using Semiodesk.Trinity; +using System; + +namespace TrinityConsoleSample.ObjectModels +{ + // NOTE: in the ontology SoloArtist is a sub class of Artist AND Person. In C#, + // we can handle that by inheriting from one of the concrete classes and interfaces which + // represent the other classes + + /// + /// A single person who is a musical artist. + /// + [RdfClass(MUSIC.SoloArtist)] + class SoloArtist : Person, IArtist + { + #region Constructors + + public SoloArtist(Uri uri) : base(uri) { } + + #endregion + } +} diff --git a/examples/dotnet/TrinityConsoleSample/ObjectModels/Song.cs b/examples/dotnet/TrinityConsoleSample/ObjectModels/Song.cs new file mode 100644 index 0000000..2514e5b --- /dev/null +++ b/examples/dotnet/TrinityConsoleSample/ObjectModels/Song.cs @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2010 - 2019, Stardog Union. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using example; +using Semiodesk.Trinity; +using System; +using System.Collections.Generic; + +namespace TrinityConsoleSample.ObjectModels +{ + /// + /// A music recording that is a single work of music. + /// + [RdfClass(MUSIC.Song)] + public class Song : Resource + { + + #region Members + + /// + /// The name of an entity. + /// + [RdfProperty(MUSIC.name)] + public string Name { get; set; } + + /// + /// A person or a group of people who participated in the creation of song as a composer or a lyricist. + /// + [RdfProperty(MUSIC.writer)] + public List Writers { get; set; } + + /// + /// The length of a song in the album expressed in seconds. + /// + [RdfProperty(MUSIC.length)] + public int Length { get; set; } + + #endregion + + #region Constructors + + public Song(Uri uri) : base(uri) { } + + #endregion + } +} \ No newline at end of file diff --git a/examples/dotnet/TrinityConsoleSample/ObjectModels/Songwriter.cs b/examples/dotnet/TrinityConsoleSample/ObjectModels/Songwriter.cs new file mode 100644 index 0000000..4b2767d --- /dev/null +++ b/examples/dotnet/TrinityConsoleSample/ObjectModels/Songwriter.cs @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2010 - 2019, Stardog Union. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using example; +using Semiodesk.Trinity; +using System; + +namespace TrinityConsoleSample.ObjectModels +{ + /// + /// A person or a group of people who participated in the creation of song as a composer or a lyricist. + /// + [RdfClass(MUSIC.Songwriter)] + public class Songwriter : Person + { + #region Constructors + + public Songwriter(Uri uri) : base(uri) { } + + #endregion + } +} \ No newline at end of file diff --git a/examples/dotnet/TrinityConsoleSample/Ontologies/music_schema.ttl b/examples/dotnet/TrinityConsoleSample/Ontologies/music_schema.ttl new file mode 100644 index 0000000..8218843 --- /dev/null +++ b/examples/dotnet/TrinityConsoleSample/Ontologies/music_schema.ttl @@ -0,0 +1,76 @@ +@prefix : . +@prefix rdf: . +@prefix rdfs: . +@prefix xsd: . + +:Person a rdfs:Class ; + rdfs:label "Person" ; + rdfs:comment "A person." . + +:Artist a rdfs:Class ; + rdfs:label "Artist" ; + rdfs:comment "A person or a group of people creating and performing music." . + +:Band a rdfs:Class ; + rdfs:label "Band" ; + rdfs:comment "A music group; that is, is a group of people creating and performing music together." ; + rdfs:subClassOf :Artist . + +:SoloArtist a rdfs:Class ; + rdfs:label "SoloArtist" ; + rdfs:comment "A single person who is a musical artist." ; + rdfs:subClassOf :Artist , :Person . + +:Album a rdfs:Class ; + rdfs:label "Album" ; + rdfs:comment "A collection of songs released by an artist on physical or digital medium." . + +:Song a rdfs:Class ; + rdfs:label "Song" ; + rdfs:comment "A music recording that is a single work of music." . + +:Songwriter a rdfs:Class ; + rdfs:label "Songwriter" ; + rdfs:comment "A person or a group of people who participated in the creation of song as a composer or a lyricist." ; + rdfs:subClassOf :Person . + +:name a rdf:Property ; + rdfs:label "name" ; + rdfs:comment "The name of an entity." ; + rdfs:range xsd:string . + +:member a rdf:Property ; + rdfs:label "member" ; + rdfs:comment "A member of a band. Does not distinguish between past vs current members." ; + rdfs:domain :Band ; + rdfs:range :SoloArtist . + +:date a rdf:Property ; + rdfs:label "date" ; + rdfs:comment "The release date of an album." ; + rdfs:domain :Album ; + rdfs:range xsd:date . + +:artist a rdf:Property ; + rdfs:label "artist" ; + rdfs:comment "The artist that performed this album." ; + rdfs:domain :Album ; + rdfs:range :Artist . + +:track a rdf:Property ; + rdfs:label "track" ; + rdfs:comment "A song included in an album." ; + rdfs:domain :Album ; + rdfs:range :Song . + +:writer a rdf:Property ; + rdfs:label "writer" ; + rdfs:comment "A person or a group of people who participated in the creation of song as a composer or a lyricist." ; + rdfs:domain :Song ; + rdfs:range :Songwriter . + +:length a rdf:Property ; + rdfs:label "length" ; + rdfs:comment "The length of a song in the album expressed in seconds." ; + rdfs:domain :Song ; + rdfs:range xsd:integer . diff --git a/examples/dotnet/TrinityConsoleSample/Ontologies/rdf.ttl b/examples/dotnet/TrinityConsoleSample/Ontologies/rdf.ttl new file mode 100755 index 0000000..37bcff1 --- /dev/null +++ b/examples/dotnet/TrinityConsoleSample/Ontologies/rdf.ttl @@ -0,0 +1,125 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix owl: . +@prefix dc: . + + a owl:Ontology ; + dc:title "The RDF Concepts Vocabulary (RDF)" ; + dc:description "This is the RDF Schema for the RDF vocabulary terms in the RDF Namespace, defined in RDF 1.1 Concepts." . + +rdf:HTML a rdfs:Datatype ; + rdfs:subClassOf rdfs:Literal ; + rdfs:isDefinedBy ; + rdfs:seeAlso ; + rdfs:label "HTML" ; + rdfs:comment "The datatype of RDF literals storing fragments of HTML content" . + +rdf:langString a rdfs:Datatype ; + rdfs:subClassOf rdfs:Literal ; + rdfs:isDefinedBy ; + rdfs:seeAlso ; + rdfs:label "langString" ; + rdfs:comment "The datatype of language-tagged string values" . + +rdf:PlainLiteral a rdfs:Datatype ; + rdfs:isDefinedBy ; + rdfs:subClassOf rdfs:Literal ; + rdfs:seeAlso ; + rdfs:label "PlainLiteral" ; + rdfs:comment "The class of plain (i.e. untyped) literal values, as used in RIF and OWL 2" . + +rdf:type a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "type" ; + rdfs:comment "The subject is an instance of a class." ; + rdfs:range rdfs:Class ; + rdfs:domain rdfs:Resource . + +rdf:Property a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Property" ; + rdfs:comment "The class of RDF properties." ; + rdfs:subClassOf rdfs:Resource . + +rdf:Statement a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Statement" ; + rdfs:subClassOf rdfs:Resource ; + rdfs:comment "The class of RDF statements." . + +rdf:subject a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "subject" ; + rdfs:comment "The subject of the subject RDF statement." ; + rdfs:domain rdf:Statement ; + rdfs:range rdfs:Resource . + +rdf:predicate a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "predicate" ; + rdfs:comment "The predicate of the subject RDF statement." ; + rdfs:domain rdf:Statement ; + rdfs:range rdfs:Resource . + +rdf:object a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "object" ; + rdfs:comment "The object of the subject RDF statement." ; + rdfs:domain rdf:Statement ; + rdfs:range rdfs:Resource . + +rdf:Bag a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Bag" ; + rdfs:comment "The class of unordered containers." ; + rdfs:subClassOf rdfs:Container . + +rdf:Seq a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Seq" ; + rdfs:comment "The class of ordered containers." ; + rdfs:subClassOf rdfs:Container . + +rdf:Alt a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Alt" ; + rdfs:comment "The class of containers of alternatives." ; + rdfs:subClassOf rdfs:Container . + +rdf:value a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "value" ; + rdfs:comment "Idiomatic property used for structured values." ; + rdfs:domain rdfs:Resource ; + rdfs:range rdfs:Resource . + +rdf:List a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "List" ; + rdfs:comment "The class of RDF Lists." ; + rdfs:subClassOf rdfs:Resource . + +rdf:nil a rdf:List ; + rdfs:isDefinedBy ; + rdfs:label "nil" ; + rdfs:comment "The empty list, with no items in it. If the rest of a list is nil then the list has no more items in it." . + +rdf:first a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "first" ; + rdfs:comment "The first item in the subject RDF list." ; + rdfs:domain rdf:List ; + rdfs:range rdfs:Resource . + +rdf:rest a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "rest" ; + rdfs:comment "The rest of the subject RDF list after the first item." ; + rdfs:domain rdf:List ; + rdfs:range rdf:List . + +rdf:XMLLiteral a rdfs:Datatype ; + rdfs:subClassOf rdfs:Literal ; + rdfs:isDefinedBy ; + rdfs:label "XMLLiteral" ; + rdfs:comment "The datatype of XML literal values." . diff --git a/examples/dotnet/TrinityConsoleSample/Ontologies/rdfs.ttl b/examples/dotnet/TrinityConsoleSample/Ontologies/rdfs.ttl new file mode 100755 index 0000000..56c8c2a --- /dev/null +++ b/examples/dotnet/TrinityConsoleSample/Ontologies/rdfs.ttl @@ -0,0 +1,109 @@ +@prefix rdf: . +@prefix rdfs: . +@prefix owl: . +@prefix dc: . + + a owl:Ontology ; + dc:title "The RDF Schema vocabulary (RDFS)" . + +rdfs:Resource a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Resource" ; + rdfs:comment "The class resource, everything." . + +rdfs:Class a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Class" ; + rdfs:comment "The class of classes." ; + rdfs:subClassOf rdfs:Resource . + +rdfs:subClassOf a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "subClassOf" ; + rdfs:comment "The subject is a subclass of a class." ; + rdfs:range rdfs:Class ; + rdfs:domain rdfs:Class . + +rdfs:subPropertyOf a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "subPropertyOf" ; + rdfs:comment "The subject is a subproperty of a property." ; + rdfs:range rdf:Property ; + rdfs:domain rdf:Property . + +rdfs:comment a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "comment" ; + rdfs:comment "A description of the subject resource." ; + rdfs:domain rdfs:Resource ; + rdfs:range rdfs:Literal . + +rdfs:label a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "label" ; + rdfs:comment "A human-readable name for the subject." ; + rdfs:domain rdfs:Resource ; + rdfs:range rdfs:Literal . + +rdfs:domain a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "domain" ; + rdfs:comment "A domain of the subject property." ; + rdfs:range rdfs:Class ; + rdfs:domain rdf:Property . + +rdfs:range a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "range" ; + rdfs:comment "A range of the subject property." ; + rdfs:range rdfs:Class ; + rdfs:domain rdf:Property . + +rdfs:seeAlso a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "seeAlso" ; + rdfs:comment "Further information about the subject resource." ; + rdfs:range rdfs:Resource ; + rdfs:domain rdfs:Resource . + +rdfs:isDefinedBy a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:subPropertyOf rdfs:seeAlso ; + rdfs:label "isDefinedBy" ; + rdfs:comment "The defininition of the subject resource." ; + rdfs:range rdfs:Resource ; + rdfs:domain rdfs:Resource . + +rdfs:Literal a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Literal" ; + rdfs:comment "The class of literal values, eg. textual strings and integers." ; + rdfs:subClassOf rdfs:Resource . + +rdfs:Container a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Container" ; + rdfs:subClassOf rdfs:Resource ; + rdfs:comment "The class of RDF containers." . + +rdfs:ContainerMembershipProperty a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "ContainerMembershipProperty" ; + rdfs:comment """The class of container membership properties, rdf:_1, rdf:_2, ..., + all of which are sub-properties of 'member'.""" ; + rdfs:subClassOf rdf:Property . + +rdfs:member a rdf:Property ; + rdfs:isDefinedBy ; + rdfs:label "member" ; + rdfs:comment "A member of the subject resource." ; + rdfs:domain rdfs:Resource ; + rdfs:range rdfs:Resource . + +rdfs:Datatype a rdfs:Class ; + rdfs:isDefinedBy ; + rdfs:label "Datatype" ; + rdfs:comment "The class of RDF datatypes." ; + rdfs:subClassOf rdfs:Class . + + rdfs:seeAlso . diff --git a/examples/dotnet/TrinityConsoleSample/Program.cs b/examples/dotnet/TrinityConsoleSample/Program.cs new file mode 100644 index 0000000..af8d12c --- /dev/null +++ b/examples/dotnet/TrinityConsoleSample/Program.cs @@ -0,0 +1,202 @@ +/* + * Copyright (c) 2010 - 2019, Stardog Union. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using System; +using System.IO; +using System.Linq; +using System.Reflection; +using TrinityConsoleSample.ObjectModels; +using Semiodesk.Trinity; +using Semiodesk.Trinity.Store; +using VDS.RDF; + +namespace TrinityConsoleSample +{ + class Program + { + + /// + /// The model we are working on + /// + static IModel Model { get; set; } + + + static void Main(string[] args) + { + // TODO: Change the connection string for your Stardog instance's host, port and credentials + const string connectionString = "provider=stardog;host=http://localhost:5820;uid=admin;pw=admin;sid=music"; + + OntologyDiscovery.AddAssembly(Assembly.GetExecutingAssembly()); + MappingDiscovery.RegisterCallingAssembly(); + + // dotNetRDF HTTP call debugging (will print to STDOUT) + + //Options.HttpDebugging = true; + + // NOTE: Note: When full debugging is used the HTTP response stream is consumed, + // this may cause dotNetRDF to throw different errors to those normally seen because + // the stream the code expects has already been consumed. + //Options.HttpFullDebugging = true; + + // Load the stardog store provider + StoreFactory.LoadProvider(); + + // Connect to the stardog store + IStore store = StoreFactory.CreateStore(connectionString); + store.InitializeFromConfiguration(Path.Combine(Environment.CurrentDirectory, "ontologies.config")); + + // Uncomment the following line to write all SPARQL queries to + // STDERR (useful for debugging) + // store.Log = (query) => Console.Error.WriteLine(query); + + // A model (named graph) is where we collect resources that logically belong together + Model = store.GetModel(new Uri("http://stardog.com/tutorial")); + + + #region using reasoning with LINQ + + var artistsWithReasoning = Model.AsQueryable(true); + + Console.WriteLine($"With reasoning set to 'true', the artists query returned {artistsWithReasoning.Count()} records"); + + var artistsWithoutReasoning = Model.AsQueryable(false); + + Console.WriteLine($"With reasoning set to 'false', the artists query returned {artistsWithoutReasoning.Count()} records"); + + #endregion + + #region paging through items using LINQ + + const int PAGE_SIZE = 4; + const int MAX_NUMBER_OF_PAGES = 8; + + var allBands = Model.AsQueryable() + .OrderBy((b) => b.Name); + + // loop through pages of bands + + for (int n = 0; n < MAX_NUMBER_OF_PAGES; n++) + { + Console.WriteLine($"Fetching {PAGE_SIZE} bands from page {n + 1}..."); + + foreach (Band b in allBands.Skip(n * PAGE_SIZE).Take(PAGE_SIZE)) + { + Console.WriteLine($"Band: {b.Name}"); + + foreach (SoloArtist sa in b.Members) + { + Console.WriteLine($"\tMember: {sa.Name}"); + } + } + } + + #endregion + + const string SEARCH_STRING = "the beatles"; + + #region filtering items using - SPARQL + + Console.WriteLine($"Get the members of bands that start with \"{SEARCH_STRING}\" using SPARQL"); + + string sparqlQuery = $@"PREFIX rdf: + PREFIX music: + SELECT ?member ?member_name + FROM + WHERE {{ + ?band rdf:type music:Band; + music:name ?name; + music:member ?member . + ?member music:name ?member_name . + FILTER(REGEX( ?name, '^{SEARCH_STRING}', 'i')) + }}"; + + var results = Model.ExecuteQuery(new SparqlQuery(sparqlQuery)); + + var bindings = results.GetBindings() + .ToList(); + + if (bindings.Count() > 0) + { + Console.WriteLine($"Found {bindings.Count()} matching members"); + + foreach (var binding in bindings) + { + Console.WriteLine($"\tMember: {binding.Values.FirstOrDefault().ToString()}"); + } + } + + #endregion + + #region filtering items using - LINQ + + Console.WriteLine($"Find bands that start with \"{SEARCH_STRING}\" using LINQ"); + + var matchingBands = from band in Model.AsQueryable() + where band.Name.StartsWith(SEARCH_STRING, StringComparison.InvariantCultureIgnoreCase) + select band; + + Console.WriteLine($"Found {matchingBands.Count()} band(s) that match!"); + + Console.WriteLine("Printing the members of the first matching band"); + + foreach (var m in matchingBands.FirstOrDefault().Members) + { + Console.WriteLine($"Name: {m.Name}"); + } + + // Get all the albums by the first band from our result set... + + var firstBand = matchingBands.FirstOrDefault(); + + var albums = from album in Model.AsQueryable() + where album.Artist.Uri.Equals(firstBand.Uri) + select album; + + int albumCount = albums.Count(); + + Console.WriteLine($"Band {firstBand.Name} has {albumCount} albums"); + + // Grab a random album... + + var rand = new Random(); + + var randomAlbum = albums.Skip(rand.Next(albumCount)) + .Take(1) + .FirstOrDefault(); + + // Print the track list... + + Console.WriteLine($"Track list for album '{randomAlbum.Name}' by {randomAlbum.Artist.Name}:"); + + foreach( var track in randomAlbum.Tracks ) + { + Console.WriteLine($"\tTrack: {track.Name}, Length: {TimeSpan.FromSeconds(track.Length).TotalMinutes.ToString("0.##")}"); + + // Print the track's writers... + + foreach ( var writer in track.Writers) + { + Console.WriteLine($"\t\tWritten by: {writer.Name}"); + } + } + + // Print the album's length... + + int totalLength = randomAlbum.Tracks.Sum(s => s.Length); + Console.WriteLine($"Total length is {TimeSpan.FromSeconds(totalLength).TotalMinutes.ToString("0.##")}"); + + #endregion + } + } +} diff --git a/examples/dotnet/TrinityConsoleSample/TrinityConsoleSample.csproj b/examples/dotnet/TrinityConsoleSample/TrinityConsoleSample.csproj new file mode 100644 index 0000000..d30bd1e --- /dev/null +++ b/examples/dotnet/TrinityConsoleSample/TrinityConsoleSample.csproj @@ -0,0 +1,26 @@ + + + + Exe + netcoreapp2.1 + TrinityConsoleSample.Program + + + + + + + + Always + + + Always + + + Always + + + Always + + + diff --git a/examples/dotnet/TrinityConsoleSample/ontologies.config b/examples/dotnet/TrinityConsoleSample/ontologies.config new file mode 100644 index 0000000..ebfe058 --- /dev/null +++ b/examples/dotnet/TrinityConsoleSample/ontologies.config @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/examples/dotnet/build.gradle b/examples/dotnet/build.gradle new file mode 100644 index 0000000..f04e5e4 --- /dev/null +++ b/examples/dotnet/build.gradle @@ -0,0 +1,18 @@ +task DotnetClean (type:Exec){ + commandLine 'dotnet', 'clean', '-c', 'Release', '-v', 'normal', project.solution +} + +task DotnetCompile (type:Exec, dependsOn: DotnetClean){ + commandLine 'dotnet', 'build', '-c', 'Release', '-v', 'normal', project.solution +} + +task DotnetRun (type:Exec, dependsOn: DotnetCompile){ + workingDir './TrinityConsoleSample' + commandLine 'dotnet', 'run', '-c', 'Release', '-v', 'normal', '--no-build' +} + +task compileDotnet (dependsOn: DotnetCompile){ +} + +task runDotnet (dependsOn: DotnetRun) { +} diff --git a/examples/dotnet/gradle.properties b/examples/dotnet/gradle.properties new file mode 100644 index 0000000..684cb7c --- /dev/null +++ b/examples/dotnet/gradle.properties @@ -0,0 +1,2 @@ +solution=StardogDotNetSamples.sln + diff --git a/examples/service/main/src/com/complexible/stardog/examples/service/ExampleService.java b/examples/service/main/src/com/complexible/stardog/examples/service/ExampleService.java index 4a525f4..5ab969f 100644 --- a/examples/service/main/src/com/complexible/stardog/examples/service/ExampleService.java +++ b/examples/service/main/src/com/complexible/stardog/examples/service/ExampleService.java @@ -16,6 +16,7 @@ package com.complexible.stardog.examples.service; import java.io.InputStream; +import java.util.function.Function; import java.util.function.IntFunction; import com.complexible.common.base.Strings2; @@ -74,9 +75,9 @@ public boolean canEvaluate(final IRI theIRI) { } @Override - public PlanNode translate(IRI iri, PlanNode planNode, IntFunction intFunction, boolean silent) { + public PlanNode translate(IRI iri, PlanNode body, IntFunction varNames, final Function varAllocator, boolean silent) { return PlanNodes.service() - .query(createQuery(iri, planNode)) + .query(createQuery(iri, body)) .silent(silent) .build(); } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 2322723..94336fc 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4eda8a7..115e6ac 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Thu Jan 18 11:13:40 HST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.10-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.2-bin.zip diff --git a/gradlew b/gradlew index 91a7e26..cccdd3d 100755 --- a/gradlew +++ b/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -6,20 +6,38 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -30,6 +48,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,31 +59,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -90,7 +89,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -114,6 +113,7 @@ fi if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` @@ -154,11 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index aec9973..e95643d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -8,14 +8,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +46,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/readme.md b/readme.md index c28bd4a..af3fb25 100644 --- a/readme.md +++ b/readme.md @@ -9,12 +9,12 @@ well as examples of how to use some of the extension points within Stardog. First, you'll need a valid Stardog download. -For the examples in `examples/api`, `example/foaf`, and `examples/function`, you'll need [Gradle](http://www.gradle.org/). +You can use the included Gradle Wrapper script to build the examples in `examples/api`, `example/foaf`, `examples/function`. To compile or run the examples, gradle will automatically download the dependencies from our public maven repository: ```bash -gradle compileJava +$ ./gradlew compileJava ``` To run the examples, they require a valid `$STARDOG_HOME`; you can provide this via the parameter `stardog.home` @@ -24,9 +24,37 @@ To run any of the examples, you can use the Gradle `execute` task. By default, program, but you can specify the fully-qualified class name of any of the other examples using the `mainClass` parameter. ```java -gradle execute -PmainClass=com.complexible.stardog.examples.api.ICVExample +$ ./gradlew execute -PmainClass=com.complexible.stardog.examples.api.ICVExample ``` +### .NET Examples + +To compile the .NET examples, you will need to install [.NET Core](https://dotnet.microsoft.com/download). Make sure that the `dotnet` tool is on your `PATH` + +While you can build the sample with the latest version of the .NET Core SDK you will need .NET Core runtime installed to **run** the example. You can download it from [here](https://dotnet.microsoft.com/download/dotnet-core/2.1) - you can verify which .NET Core runtimes you have installed by running: + +```bash +dotnet --list-runtimes +``` + +Once you have installed .NET Core SDK and runtime,you can build the sample with the following command: + +```bash +$ ./gradlew compileDotnet +``` + +To run the .NET examples you should have Stardog running locally and listening on port 5820 (you can change this by editing the connection string in `./examples/dotnet/TrinityConsoleSample/Program.cs`. In addition, the example expects Stardog to have a database named 'music' loaded with the data from `./examples/dotnet/TrinityConsoleSample/Ontologies/music_schema.ttl` and [music.ttl.gz](https://github.com/stardog-union/stardog-tutorials/blob/master/music/music.ttl.gz) in a named graph called `http://stardog.com/tutorial` + +You can run the sample with the following command (NOTE: the following command will automatically rebuild the sample): + +```bash +$ ./gradlew runDotnet +``` + +The sample project will connect to Stardog and execute several queries using SPARQL and LINQ. It will print the results to the console. + +For additional information see the DotNet Samples' README file - `./examples/dotnet/README.md` + ## Generating Documentation The Stardog [documentation](http://docs.stardog.com) and its [javadocs](http://docs.stardog.com/java/snarl) are a good @@ -36,13 +64,13 @@ place to start. But some examples in this repository are annotated using Markdow If you don't have Docco installed, it's pretty easy to get started: ```bash -sudo npm install -g docco +$ sudo npm install -g docco ``` Then, you can run it directly against any example: ```bash -docco -o docs main/src/com/complexible/stardog/api/ConnectionAPIExample.java +$ docco -o docs main/src/com/complexible/stardog/api/ConnectionAPIExample.java ``` Or you can use the supplied `gradle docs` task in each build file that will run Docco against all annotated source files. @@ -69,6 +97,7 @@ the `ServiceLoader` to make them up. 1. [CSV example](./examples/cli/virtual/csv/readme.md) 1. [Docs Examples](./examples/docs/readme.md) 1. [Database Archetype Extensibility](./examples/foaf/readme.md) +1. [DotNet Example](./examples/dotnet/README.md) 1. [Function Extensibility](./examples/function/readme.md) 1. [Transaction Listener](./examples/listener/readme.md) 1. [Cloud Foundry Example Application](https://github.com/stardog-union/cf-example) diff --git a/settings.gradle b/settings.gradle index c2a09bd..a1eade8 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1 @@ -include "examples:api", "examples:function", "examples:analyzer", "examples:foaf", "examples:docs", "examples:connectable", "examples:service", "examples:describe", "examples:http_handler" +include "examples:api", "examples:function", "examples:analyzer", "examples:foaf", "examples:docs", "examples:connectable", "examples:service", "examples:describe", "examples:http_handler","examples:dotnet"