-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See #6
- Loading branch information
Showing
11 changed files
with
263 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::errors::{ErrorKind, Result}; | ||
use crate::fsshttpb::data::exguid::ExGuid; | ||
use crate::one::property::object_reference::ObjectReference; | ||
use crate::one::property::PropertyType; | ||
use crate::one::property_set::PropertySetId; | ||
use crate::onestore::object::Object; | ||
|
||
#[derive(Debug)] | ||
pub(crate) struct Data { | ||
pub(crate) paragraphs: Vec<ExGuid>, | ||
} | ||
|
||
pub(crate) fn parse(object: &Object) -> Result<Data> { | ||
if object.id() != PropertySetId::InkAnalysis.as_jcid() { | ||
return Err(ErrorKind::MalformedOneNoteFileData( | ||
format!("unexpected object type: 0x{:X}", object.id().0).into(), | ||
) | ||
.into()); | ||
} | ||
|
||
let paragraphs = | ||
ObjectReference::parse_vec(PropertyType::InkAnalysisReference, object)?.unwrap_or_default(); | ||
|
||
Ok(Data { paragraphs }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::errors::{ErrorKind, Result}; | ||
use crate::fsshttpb::data::exguid::ExGuid; | ||
use crate::one::property::object_reference::ObjectReference; | ||
use crate::one::property::PropertyType; | ||
use crate::one::property_set::PropertySetId; | ||
use crate::onestore::object::Object; | ||
|
||
#[derive(Debug)] | ||
pub(crate) struct Data { | ||
pub(crate) words: Vec<ExGuid>, | ||
} | ||
|
||
pub(crate) fn parse(object: &Object) -> Result<Data> { | ||
if object.id() != PropertySetId::InkAnalysisLine.as_jcid() { | ||
return Err(ErrorKind::MalformedOneNoteFileData( | ||
format!("unexpected object type: 0x{:X}", object.id().0).into(), | ||
) | ||
.into()); | ||
} | ||
|
||
let words = | ||
ObjectReference::parse_vec(PropertyType::InkAnalysisReference, object)?.unwrap_or_default(); | ||
|
||
Ok(Data { words }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use crate::errors::{ErrorKind, Result}; | ||
use crate::fsshttpb::data::exguid::ExGuid; | ||
use crate::one::property::object_reference::ObjectReference; | ||
use crate::one::property::PropertyType; | ||
use crate::one::property_set::PropertySetId; | ||
use crate::onestore::object::Object; | ||
|
||
#[derive(Debug)] | ||
pub(crate) struct Data { | ||
pub(crate) lines: Vec<ExGuid>, | ||
} | ||
|
||
pub(crate) fn parse(object: &Object) -> Result<Data> { | ||
if object.id() != PropertySetId::InkAnalysisParagraph.as_jcid() { | ||
return Err(ErrorKind::MalformedOneNoteFileData( | ||
format!("unexpected object type: 0x{:X}", object.id().0).into(), | ||
) | ||
.into()); | ||
} | ||
|
||
let lines = | ||
ObjectReference::parse_vec(PropertyType::InkAnalysisReference, object)?.unwrap_or_default(); | ||
|
||
Ok(Data { lines }) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
use crate::errors::{ErrorKind, Result}; | ||
use crate::one::property::{simple, PropertyType}; | ||
use crate::one::property_set::PropertySetId; | ||
use crate::onestore::object::Object; | ||
use itertools::Itertools; | ||
use widestring::U16String; | ||
|
||
#[derive(Debug)] | ||
pub(crate) struct Data { | ||
pub(crate) alternatives: Vec<String>, | ||
pub(crate) language_code: Option<u32>, | ||
} | ||
|
||
pub(crate) fn parse(object: &Object) -> Result<Data> { | ||
if object.id() != PropertySetId::InkAnalysisWord.as_jcid() { | ||
return Err(ErrorKind::MalformedOneNoteFileData( | ||
format!("unexpected object type: 0x{:X}", object.id().0).into(), | ||
) | ||
.into()); | ||
} | ||
|
||
let language_code = simple::parse_u16(PropertyType::InkAnalysisWordLanguageId, object)? | ||
.map(|value| value as u32); | ||
|
||
let alternatives = simple::parse_vec(PropertyType::InkAnalysisWordAlternatives, object)? | ||
.map(|data| { | ||
let data: Vec<_> = data | ||
.chunks_exact(2) | ||
.map(|v| u16::from_le_bytes([v[0], v[1]])) | ||
.collect(); | ||
data.split(|c| *c == 0) | ||
.filter(|chars| !chars.is_empty()) | ||
.map(|chars| { | ||
U16String::from_vec(chars.to_vec()) | ||
.to_string() | ||
.map_err(|e| e.into()) | ||
}) | ||
.collect::<Result<_>>() | ||
}) | ||
.transpose()? | ||
.ok_or_else(|| { | ||
ErrorKind::MalformedOneNoteFileData("ink analysis word has no alternatives".into()) | ||
})?; | ||
|
||
Ok(Data { | ||
alternatives, | ||
language_code, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
use crate::errors::{ErrorKind, Result}; | ||
use crate::fsshttpb::data::exguid::ExGuid; | ||
use crate::one::property_set::{ | ||
ink_analysis, ink_analysis_line, ink_analysis_paragraph, ink_analysis_word, | ||
}; | ||
use crate::onestore::object_space::ObjectSpace; | ||
use itertools::Itertools; | ||
|
||
/// The results of OCR analysis of ink handwriting. | ||
#[derive(Clone, Debug)] | ||
pub struct InkAnalysis { | ||
pub(crate) paragraphs: Vec<InkAnalysisParagraph>, | ||
} | ||
|
||
impl InkAnalysis { | ||
pub fn paragraphs(&self) -> &[InkAnalysisParagraph] { | ||
&self.paragraphs | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct InkAnalysisParagraph { | ||
pub(crate) lines: Vec<InkAnalysisLine>, | ||
} | ||
|
||
impl InkAnalysisParagraph { | ||
pub fn lines(&self) -> &[InkAnalysisLine] { | ||
&self.lines | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct InkAnalysisLine { | ||
pub(crate) words: Vec<InkAnalysisWord>, | ||
} | ||
|
||
impl InkAnalysisLine { | ||
pub fn words(&self) -> &[InkAnalysisWord] { | ||
&self.words | ||
} | ||
} | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct InkAnalysisWord { | ||
pub(crate) language_code: Option<u32>, | ||
pub(crate) alternatives: Vec<String>, | ||
} | ||
|
||
impl InkAnalysisWord { | ||
pub fn alternatives(&self) -> &[String] { | ||
&self.alternatives | ||
} | ||
} | ||
|
||
pub(crate) fn parse_ink_analysis( | ||
ink_analysis_id: ExGuid, | ||
space: &ObjectSpace, | ||
) -> Result<InkAnalysis> { | ||
let container_object = space.get_object(ink_analysis_id).ok_or_else(|| { | ||
ErrorKind::MalformedOneNoteData("ink analysis container is missing".into()) | ||
})?; | ||
let container_data = ink_analysis::parse(container_object)?; | ||
|
||
let paragraphs = container_data | ||
.paragraphs | ||
.iter() | ||
.map(|id| parse_ink_analysis_paragraph(*id, space)) | ||
.collect::<Result<_>>()?; | ||
|
||
Ok(InkAnalysis { paragraphs }) | ||
} | ||
|
||
fn parse_ink_analysis_paragraph( | ||
paragraph_id: ExGuid, | ||
space: &ObjectSpace, | ||
) -> Result<InkAnalysisParagraph> { | ||
let object = space.get_object(paragraph_id).ok_or_else(|| { | ||
ErrorKind::MalformedOneNoteData("ink analysis paragraph is missing".into()) | ||
})?; | ||
let data = ink_analysis_paragraph::parse(object)?; | ||
|
||
let lines = data | ||
.lines | ||
.iter() | ||
.map(|id| parse_ink_analysis_line(*id, space)) | ||
.collect::<Result<_>>()?; | ||
|
||
Ok(InkAnalysisParagraph { lines }) | ||
} | ||
|
||
fn parse_ink_analysis_line(line_id: ExGuid, space: &ObjectSpace) -> Result<InkAnalysisLine> { | ||
let object = space | ||
.get_object(line_id) | ||
.ok_or_else(|| ErrorKind::MalformedOneNoteData("ink analysis line is missing".into()))?; | ||
let data = ink_analysis_line::parse(object)?; | ||
|
||
let words = data | ||
.words | ||
.iter() | ||
.map(|id| parse_ink_analysis_word(*id, space)) | ||
.collect::<Result<_>>()?; | ||
|
||
Ok(InkAnalysisLine { words }) | ||
} | ||
|
||
fn parse_ink_analysis_word(word_id: ExGuid, space: &ObjectSpace) -> Result<InkAnalysisWord> { | ||
let object = space | ||
.get_object(word_id) | ||
.ok_or_else(|| ErrorKind::MalformedOneNoteData("ink analysis word is missing".into()))?; | ||
let data = ink_analysis_word::parse(object)?; | ||
|
||
Ok(InkAnalysisWord { | ||
language_code: data.language_code, | ||
alternatives: data.alternatives, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98303,6 +98303,7 @@ Notebook { | |
}, | ||
), | ||
], | ||
ink_analysis: None, | ||
}, | ||
], | ||
}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98300,6 +98300,7 @@ Section { | |
}, | ||
), | ||
], | ||
ink_analysis: None, | ||
}, | ||
], | ||
}, | ||
|