Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkovsky committed Dec 28, 2024
1 parent f01777c commit a25db78
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 37 deletions.
12 changes: 6 additions & 6 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,14 @@ fn json_to_schema(json: &str) -> PyResult<PyArrowType<ArrowSchema>> {
#[pyfunction]
pub fn language_model_home() -> PyResult<String> {
let Some(p) = lance_index::scalar::inverted::language_model_home() else {
return Err(pyo3::exceptions::PyValueError::new_err(format!(
"Failed to get language model home"
)));
return Err(pyo3::exceptions::PyValueError::new_err(
"Failed to get language model home",
));
};
let Some(pstr) = p.to_str() else {
return Err(pyo3::exceptions::PyValueError::new_err(format!(
"Failed to convert language model home to str"
)));
return Err(pyo3::exceptions::PyValueError::new_err(
"Failed to convert language model home to str",
));
};
Ok(String::from(pstr))
}
Expand Down
4 changes: 2 additions & 2 deletions rust/lance-index/src/scalar/inverted/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub fn language_model_home() -> Option<PathBuf> {
#[cfg(feature = "tokenizer-common")]
trait TokenizerBuilder: Sized {
type Config: serde::de::DeserializeOwned + Default;
fn load(p: &PathBuf) -> Result<Self> {
fn load(p: &std::path::Path) -> Result<Self> {
if !p.is_dir() {
return Err(Error::io(
format!("{} is not a valid directory", p.display()),
Expand All @@ -214,7 +214,7 @@ trait TokenizerBuilder: Sized {
Self::new(config, p)
}

fn new(config: Self::Config, root: &PathBuf) -> Result<Self>;
fn new(config: Self::Config, root: &std::path::Path) -> Result<Self>;

fn build(&self) -> Result<tantivy::tokenizer::TextAnalyzerBuilder>;
}
19 changes: 5 additions & 14 deletions rust/lance-index/src/scalar/inverted/tokenizer/jieba.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright The Lance Authors

use std::path::PathBuf;
use std::path::{Path, PathBuf};

use super::TokenizerBuilder;
use lance_core::{Error, Result};
use serde::{Deserialize, Serialize};
use snafu::{location, Location};

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Default)]
pub struct JiebaConfig {
main: Option<String>,
users: Option<Vec<String>>,
}

impl Default for JiebaConfig {
fn default() -> Self {
Self {
main: Default::default(),
users: Default::default(),
}
}
}

pub struct JiebaBuilder {
root: PathBuf,
config: JiebaConfig,
Expand All @@ -47,10 +38,10 @@ impl JiebaBuilder {
impl TokenizerBuilder for JiebaBuilder {
type Config = JiebaConfig;

fn new(config: Self::Config, root: &PathBuf) -> Result<Self> {
Ok(JiebaBuilder {
fn new(config: Self::Config, root: &Path) -> Result<Self> {
Ok(Self {
config,
root: root.clone(),
root: root.to_path_buf(),
})
}

Expand Down
20 changes: 5 additions & 15 deletions rust/lance-index/src/scalar/inverted/tokenizer/lindera.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright The Lance Authors

use std::path::PathBuf;
use std::path::{Path, PathBuf};

use super::TokenizerBuilder;
use lance_core::{Error, Result};
Expand All @@ -17,23 +17,13 @@ use serde::{Deserialize, Serialize};
use serde_json::{Map, Value};
use snafu::{location, Location};

#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Default)]
pub struct LinderaConfig {
main: Option<String>,
user: Option<String>,
user_kind: Option<String>,
}

impl Default for LinderaConfig {
fn default() -> Self {
Self {
main: Default::default(),
user: Default::default(),
user_kind: Default::default(),
}
}
}

pub struct LinderaBuilder {
root: PathBuf,
config: LinderaConfig,
Expand Down Expand Up @@ -73,10 +63,10 @@ impl LinderaBuilder {
impl TokenizerBuilder for LinderaBuilder {
type Config = LinderaConfig;

fn new(config: Self::Config, root: &PathBuf) -> Result<Self> {
Ok(LinderaBuilder {
fn new(config: Self::Config, root: &Path) -> Result<Self> {
Ok(Self {
config,
root: root.clone(),
root: root.to_path_buf(),
})
}

Expand Down

0 comments on commit a25db78

Please sign in to comment.