Skip to content

Commit

Permalink
Map corpus/document annotations but do not map the ones of the "salt"…
Browse files Browse the repository at this point in the history
… namespace
  • Loading branch information
thomaskrause committed Aug 6, 2024
1 parent 299e3d8 commit f5ca1f7
Show file tree
Hide file tree
Showing 4 changed files with 1,143 additions and 1,134 deletions.
43 changes: 30 additions & 13 deletions src/importer/saltxml/corpus_structure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use graphannis::{
use graphannis_core::graph::ANNIS_NS;
use itertools::Itertools;

use super::{get_element_id, get_features, resolve_element, SaltObject, SaltType};
use super::{get_annotations, get_element_id, get_features, resolve_element, SaltObject, SaltType};

pub(super) struct SaltCorpusStructureMapper {}

Expand Down Expand Up @@ -38,8 +38,6 @@ impl SaltCorpusStructureMapper {
.children()
.filter(|t| t.tag_name().name() == "sCorpusGraphs")
{
// TODO: map corpus graph labels

// Get all nodes
let nodes = cg
.children()
Expand Down Expand Up @@ -74,15 +72,17 @@ impl SaltCorpusStructureMapper {
feature_node.attribute("value").unwrap_or_default(),
);

if annos_ns == Some("salt") && anno_name == "SNAME" {
// Only map this specific feature as document name
if salt_type == SaltType::Document {
updates.add_event(UpdateEvent::AddNodeLabel {
node_name: node_name.to_string(),
anno_ns: ANNIS_NS.to_string(),
anno_name: "doc".to_string(),
anno_value: anno_value.to_string(),
})?;
if annos_ns == Some("salt") {
if anno_name == "SNAME" {
// Only map this specific feature as document name
if salt_type == SaltType::Document {
updates.add_event(UpdateEvent::AddNodeLabel {
node_name: node_name.to_string(),
anno_ns: ANNIS_NS.to_string(),
anno_name: "doc".to_string(),
anno_value: anno_value.to_string(),
})?;
}
}
} else {
updates.add_event(UpdateEvent::AddNodeLabel {
Expand All @@ -93,8 +93,25 @@ impl SaltCorpusStructureMapper {
})?;
}
}
// Add annotations
for anno_node in get_annotations(node) {
let annos_ns = anno_node.attribute("namespace");
if annos_ns != Some("salt") {
let anno_name = anno_node.attribute("name").ok_or_else(|| {
anyhow!("Missing \"name\" attribute for node \"{node_name}\"")
})?;
let anno_value = SaltObject::from(
anno_node.attribute("value").unwrap_or_default(),
);

// TODO: map annotations (that are not features)
updates.add_event(UpdateEvent::AddNodeLabel {
node_name: node_name.to_string(),
anno_ns: annos_ns.unwrap_or_default().to_string(),
anno_name: anno_name.to_string(),
anno_value: anno_value.to_string(),
})?;
}
}
}
_ => {}
}
Expand Down
1 change: 1 addition & 0 deletions src/importer/saltxml/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ impl<'a, 'input> DocumentMapper<'a, 'input> {
}

fn map_media_datasources(&mut self, updates: &mut GraphUpdate) -> Result<()> {
// TODO: Map time codes from the SAudioRelation as annis::time
for media_node in self
.nodes
.iter()
Expand Down
Loading

0 comments on commit f5ca1f7

Please sign in to comment.