WikiDataLib 1.1.4

dotnet add package WikiDataLib --version 1.1.4
                    
NuGet\Install-Package WikiDataLib -Version 1.1.4
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WikiDataLib" Version="1.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="WikiDataLib" Version="1.1.4" />
                    
Directory.Packages.props
<PackageReference Include="WikiDataLib" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add WikiDataLib --version 1.1.4
                    
#r "nuget: WikiDataLib, 1.1.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package WikiDataLib@1.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=WikiDataLib&version=1.1.4
                    
Install as a Cake Addin
#tool nuget:?package=WikiDataLib&version=1.1.4
                    
Install as a Cake Tool

WikiDataLib

A modern, robust .NET library for accessing WikiData SPARQL queries to search and retrieve person information.

NuGet License: MIT

Features

Modern & Safe: C# 8.0 with nullable reference types
Async/Await: Full async support with cancellation tokens
Well-tested: Comprehensive test coverage (17 tests)
Error Handling: Robust error handling with meaningful exceptions
Cross-platform: Targets .NET Standard 2.0 and .NET 10
Production-ready: Input validation, resource management, XML documentation

Installation

dotnet add package WikiDataLib

Or via Package Manager:

Install-Package WikiDataLib

Quick Start

using WikiDataLib;
using System.Threading;

// Search for people by name
var people = await WikiData.WikiPeopleSearchAsync("Ada Lovelace");
foreach (var person in people)
{
    Console.WriteLine($"{person.Name}: {person.Description}");
}

// Get a specific person by WikiData ID (numeric part of Q-identifier)
var elvis = await WikiData.GetWikiPersonAsync(303); // Q303 = Elvis Presley
Console.WriteLine($"{elvis.Name} was born on {elvis.Birthday:yyyy-MM-dd}");

Advanced Usage

Cancellation Support

using var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(5));

try
{
    var people = await WikiData.WikiPeopleSearchAsync("Pope", cts.Token);
}
catch (TaskCanceledException)
{
    Console.WriteLine("Search was cancelled");
}

Error Handling

try
{
    var person = await WikiData.GetWikiPersonAsync(999999999);
}
catch (InvalidOperationException ex)
{
    Console.WriteLine($"Person not found: {ex.Message}");
}
catch (HttpRequestException ex)
{
    Console.WriteLine($"Network error: {ex.Message}");
}

API Reference

WikiData.WikiPeopleSearchAsync

Searches for people in WikiData by name.

public static Task<Collection<WikiPerson>> WikiPeopleSearchAsync(
    string searchString, 
    CancellationToken cancellationToken = default)

Parameters:

  • searchString - The search term to find people (required, non-empty)
  • cancellationToken - Cancellation token to cancel the operation (optional)

Returns:

  • Collection<WikiPerson> - Collection of matching people (empty if no results)

Exceptions:

  • ArgumentException - When searchString is null, empty, or whitespace
  • HttpRequestException - When the WikiData API request fails
  • JsonException - When the response cannot be parsed
  • TaskCanceledException - When the operation is cancelled

WikiData.GetWikiPersonAsync

Gets a specific person from WikiData by their numeric ID.

public static Task<WikiPerson> GetWikiPersonAsync(
    int id, 
    CancellationToken cancellationToken = default)

Parameters:

  • id - The WikiData entity ID (numeric part of Q-identifier, e.g., 303 for Q303)
  • cancellationToken - Cancellation token to cancel the operation (optional)

Returns:

  • WikiPerson - The person's information

Exceptions:

  • ArgumentOutOfRangeException - When id is less than or equal to 0
  • InvalidOperationException - When no person is found with the given ID
  • HttpRequestException - When the WikiData API request fails
  • JsonException - When the response cannot be parsed
  • TaskCanceledException - When the operation is cancelled

WikiPerson Class

Represents a person entity from WikiData.

public class WikiPerson
{
    public int Id { get; set; }
    public string? Name { get; set; }
    public string? Description { get; set; }
    public DateTime? Birthday { get; set; }
    public DateTime? Death { get; set; }
    public string? Image { get; set; }
    public string? Link { get; set; }
}

Properties:

  • Id - WikiData numeric identifier
  • Name - Person's name (nullable)
  • Description - Short description of the person (nullable)
  • Birthday - Date of birth (nullable)
  • Death - Date of death (nullable, null if still alive or unknown)
  • Image - URL to person's image (nullable)
  • Link - Wikipedia article URL (nullable)

Migration Guide (v1.1.3 → v1.1.4)

Breaking Changes

1. Method Names Changed (Async Suffix)

Before (v1.1.3):

var people = await WikiData.WikiPeopleSearch("Pope");
var person = await WikiData.GetWikiPerson(303);

After (v1.1.4):

var people = await WikiData.WikiPeopleSearchAsync("Pope");
var person = await WikiData.GetWikiPersonAsync(303);
2. Nullable String Properties

Before (v1.1.3):

public string Name { get; set; }  // Non-nullable

After (v1.1.4):

public string? Name { get; set; }  // Nullable

Migration:

  • Enable nullable reference types in your project: <Nullable>enable</Nullable>
  • Add null checks when accessing WikiPerson properties
  • Or use null-forgiving operator ! if you're certain the value exists
// Recommended approach
var name = person.Name ?? "Unknown";

// Or with null-conditional
Console.WriteLine(person.Name?.ToUpper());

New Features in v1.1.4

Cancellation Token Support - Cancel long-running operations
Comprehensive Error Handling - Specific exceptions with meaningful messages
Input Validation - Validates parameters before making API calls
Security Fix - Prevents SPARQL injection attacks
Resource Management - Fixed HttpClient resource leak
XML Documentation - Full IntelliSense support

Non-Breaking Improvements

  • DateTime properties now use null instead of DateTime.MinValue for missing values
  • Better performance and reliability
  • Improved code maintainability

Examples

Find People with Special Characters

// Handles special characters and Unicode automatically
var people = await WikiData.WikiPeopleSearchAsync("O'Brien");
var german = await WikiData.WikiPeopleSearchAsync("Müller");

Check for Missing Information

var person = await WikiData.GetWikiPersonAsync(303);

if (person.Birthday.HasValue)
{
    Console.WriteLine($"Born: {person.Birthday.Value:yyyy-MM-dd}");
}

if (person.Death.HasValue)
{
    Console.WriteLine($"Died: {person.Death.Value:yyyy-MM-dd}");
}
else
{
    Console.WriteLine("Still alive or death date unknown");
}

Batch Processing with Error Handling

var ids = new[] { 303, 42, 239, 5879 };

foreach (var id in ids)
{
    try
    {
        var person = await WikiData.GetWikiPersonAsync(id);
        Console.WriteLine($"Q{id}: {person.Name}");
    }
    catch (InvalidOperationException)
    {
        Console.WriteLine($"Q{id}: Not found");
    }
}

Requirements

  • .NET Standard 2.0+ or .NET 5+
  • C# 8.0+ (for nullable reference types support)

Dependencies

  • System.Text.Json (10.0.0)
  • System.ComponentModel.Annotations (5.0.0)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Repository

Changelog

v1.1.4 (Current)

  • BREAKING: Renamed methods with Async suffix
  • BREAKING: String properties now nullable
  • Added cancellation token support
  • Added comprehensive error handling
  • Added input validation
  • Fixed SPARQL injection vulnerability
  • Fixed HttpClient resource leak
  • Added XML documentation
  • Improved code quality and maintainability
  • Expanded test coverage (2 → 17 tests)

v1.1.3

  • Initial stable release
  • Basic search and get person functionality
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.1.4 91 2/6/2026
1.1.3 91 1/27/2026
1.1.2 88 1/26/2026
1.1.1 91 1/23/2026
1.1.0 93 1/14/2026
1.0.9 105 1/14/2026
1.0.8 92 1/14/2026
1.0.7 92 1/14/2026
1.0.6 190 11/28/2024
1.0.5 164 11/27/2024
1.0.4 161 11/27/2024
1.0.3 780 1/27/2020
1.0.2 678 1/27/2020