Skip to content

Commit

Permalink
chore(all): various updates
Browse files Browse the repository at this point in the history
  • Loading branch information
jgeluk committed Jan 22, 2023
1 parent d5760b6 commit d66923d
Show file tree
Hide file tree
Showing 32 changed files with 215 additions and 199 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ env_logger = "0.10.0"
mime = "0.3.16"
lazy_static = "1.4.0"
thiserror = "1.0.31"
regex = "1.6.0"
fancy-regex = "0.10.0"
colored = "2.0.0"
ignore = "0.4.18"
iref = "2.1.3"
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MIT License

Copyright (c) 2022 Enterprise Knowledge Graph Foundation.
Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
6 changes: 3 additions & 3 deletions src/class.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------

use std::{ops::Deref, sync::Arc};

use indoc::formatdoc;

use crate::{
prefix::Prefix,
Error,
FactDomain,
GraphConnection,
Parameters,
Prefix,
Prefixes,
Statement,
Transaction,
Expand Down Expand Up @@ -120,7 +120,7 @@ impl Class {

#[cfg(test)]
mod tests {
use crate::{class::Class, Prefix};
use crate::{class::Class, prefix::Prefix};

#[test]
fn test_a_class_01() {
Expand Down
2 changes: 1 addition & 1 deletion src/connectable_data_store.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------

use std::sync::{
Expand Down
2 changes: 1 addition & 1 deletion src/cursor/cursor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------

use std::{ffi::CString, fmt::Debug, ptr, sync::Arc};
Expand Down
2 changes: 1 addition & 1 deletion src/cursor/cursor_row.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------

use {
Expand Down
2 changes: 1 addition & 1 deletion src/cursor/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------

use std::ffi::CStr;
Expand Down
2 changes: 1 addition & 1 deletion src/cursor/opened_cursor.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------

use {
Expand Down
7 changes: 3 additions & 4 deletions src/data_store_connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------

use std::{
Expand All @@ -14,11 +14,11 @@ use std::{
};

use colored::Colorize;
use fancy_regex::Regex;
use ignore::{types::TypesBuilder, WalkBuilder};
use indoc::formatdoc;
use iref::Iri;
use mime::Mime;
use regex::Regex;

use crate::{
database_call,
Expand All @@ -39,7 +39,6 @@ use crate::{
FactDomain,
Graph,
Parameters,
Prefix,
Prefixes,
Statement,
Streamer,
Expand All @@ -50,7 +49,7 @@ use crate::{
LOG_TARGET_FILES,
TEXT_TURTLE,
};
use crate::{error::Error, ServerConnection};
use crate::{error::Error, prefix::Prefix, ServerConnection};

#[derive(Debug)]
pub struct DataStoreConnection {
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------

extern crate alloc;
Expand Down
25 changes: 14 additions & 11 deletions src/exception.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------

// extern crate libc;

use std::{
ffi::CStr,
fmt::{Display, Formatter},
panic::catch_unwind,
str::Utf8Error,
use {
crate::{
root::{CException_getExceptionName, CException_what},
Error::{self},
},
std::{
ffi::CStr,
fmt::{Display, Formatter},
panic::catch_unwind,
str::Utf8Error,
},
};

pub use crate::root::CException;
use crate::{
root::{CException_getExceptionName, CException_what},
Error::{self},
};

impl CException {
pub fn handle<F>(action: &str, f: F) -> Result<(), Error>
Expand All @@ -36,7 +38,8 @@ impl CException {
match res {
Ok(..) => Ok(()),
Err(err) => {
panic!("{err:}")
// panic!("{err:}")
Err(err)
},
}
},
Expand Down
4 changes: 2 additions & 2 deletions src/graph.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------

use std::ffi::CString;

use lazy_static::lazy_static;

use crate::{LexicalValue, Prefix};
use crate::{prefix::Prefix, LexicalValue};

lazy_static! {
pub static ref NS_RDFOX: Prefix =
Expand Down
2 changes: 1 addition & 1 deletion src/graph_connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------

use std::{
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------
#![feature(rustc_private)]
#![feature(cstr_from_bytes_until_nul)]
Expand All @@ -23,7 +23,8 @@ pub use mime::Mime;
pub use namespace::*;
pub use parameters::{FactDomain, Parameters, PersistenceMode};
pub use predicate::Predicate;
pub use prefixes::{Prefix, Prefixes, PrefixesBuilder};
pub use prefix::Prefix;
pub use prefixes::{Prefixes, PrefixesBuilder};
pub use rdf::{DataType, LexicalValue, ResourceValue, Term};
pub use role_creds::RoleCreds;
pub use server::Server;
Expand Down Expand Up @@ -82,6 +83,7 @@ mod license;
mod namespace;
mod parameters;
mod predicate;
mod prefix;
mod prefixes;
mod rdf;
mod role_creds;
Expand Down
16 changes: 12 additions & 4 deletions src/license.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------

use std::path::{Path, PathBuf};
Expand All @@ -9,15 +9,23 @@ pub const RDFOX_DEFAULT_LICENSE_FILE_NAME: &str = "RDFox.lic";
pub fn find_license(dir: &Path) -> Result<PathBuf, crate::Error> {
if dir.exists() {
let license = dir.join(RDFOX_DEFAULT_LICENSE_FILE_NAME);
tracing::debug!("Checking license file {license:?}");
tracing::debug!(
target: crate::LOG_TARGET_DATABASE,
"Checking license file {license:?}"
);
if license.exists() {
return Ok(license)
}
}
// Now check home directory ~/.RDFox/RDFox.lic
//
let license = PathBuf::from(format!("{RDFOX_HOME}/{RDFOX_DEFAULT_LICENSE_FILE_NAME}"));
tracing::debug!("Checking license file {license:?}");
let license = PathBuf::from(format!(
"{RDFOX_HOME}/{RDFOX_DEFAULT_LICENSE_FILE_NAME}"
));
tracing::debug!(
target: crate::LOG_TARGET_DATABASE,
"Checking license file {license:?}"
);
if license.exists() {
return Ok(license)
}
Expand Down
4 changes: 2 additions & 2 deletions src/namespace.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------

use iref::Iri;
use lazy_static::lazy_static;

use crate::Prefix;
use crate::prefix::Prefix;

type PrefixName<'a> = &'a str;

Expand Down
2 changes: 1 addition & 1 deletion src/parameters.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2018-2022, agnos.ai UK Ltd, all rights reserved.
// Copyright (c) 2018-2023, agnos.ai UK Ltd, all rights reserved.
//---------------------------------------------------------------

extern crate alloc;
Expand Down
4 changes: 2 additions & 2 deletions src/predicate.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::Prefix;
use crate::prefix::Prefix;

pub struct Predicate<'a> {
pub namespace: &'a Prefix,
Expand Down Expand Up @@ -54,7 +54,7 @@ impl<'a> Predicate<'a> {
mod tests {
use iref::Iri;

use crate::{predicate::Predicate, Prefix};
use crate::{predicate::Predicate, prefix::Prefix};

#[test]
fn test_predicate() {
Expand Down
63 changes: 63 additions & 0 deletions src/prefix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
use iref::{Iri, IriBuf};

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Prefix {
/// assumed to end with ':'
pub name: String,
/// assumed to end with either '/' or '#'
pub iri: IriBuf,
}

impl std::fmt::Display for Prefix {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{} <{}>", self.name.as_str(), self.iri.as_str())
}
}

impl Prefix {
pub fn declare<'a, Base: Into<Iri<'a>>>(name: &str, iri: Base) -> Self {
let iri = iri.into();
match iri.as_str().chars().last() {
Some('/') | Some('#') => {
Self {
name: name.to_string(),
iri: IriBuf::from(iri),
}
},
_ => {
Self {
name: name.to_string(),
iri: IriBuf::from_string(format!("{}/", iri)).unwrap(),
}
},
}
}

pub fn declare_from_str(name: &str, iri: &str) -> Self {
Self::declare(name, Iri::from_str(iri).unwrap())
}

pub fn with_local_name(&self, name: &str) -> Result<IriBuf, iref::Error> {
let binding = self.iri.as_iri_ref();
match binding.path().as_str().chars().last() {
Some(char) if char == '/' => {
IriBuf::new(format!("{}{}", self.iri.as_str(), name).as_str())
},
Some(char) if char == '#' => {
IriBuf::new(format!("{}{}", self.iri.as_str(), name).as_str())
},
_ => IriBuf::new(format!("{}/{}", self.iri.as_str(), name).as_str()),
}
}

#[cfg(feature = "rdftk_support")]
pub fn as_rdftk_iri_ref(&self) -> Result<rdftk_iri::IRIRef, rdftk_iri::error::Error> {
Ok(rdftk_iri::IRIRef::new(self.as_rdftk_iri()?))
}

#[cfg(feature = "rdftk_support")]
pub fn as_rdftk_iri(&self) -> Result<rdftk_iri::IRI, rdftk_iri::error::Error> {
use std::str::FromStr;
rdftk_iri::IRI::from_str(self.iri.as_str())
}
}
Loading

0 comments on commit d66923d

Please sign in to comment.