mirror of
https://github.com/TheAnachronism/docspell.git
synced 2025-06-21 18:08:25 +00:00
Use date from e-mails to set item date
This commit is contained in:
@ -43,6 +43,17 @@ case class MetaProposal(proposalType: MetaProposalType, values: NonEmptyList[Can
|
||||
|
||||
object MetaProposal {
|
||||
|
||||
def apply(pt: MetaProposalType, v0: Candidate, vm: Candidate*): MetaProposal =
|
||||
MetaProposal(pt, NonEmptyList.of(v0, vm: _*))
|
||||
|
||||
def docDate(ts: Timestamp, origin: Option[NerLabel]): MetaProposal = {
|
||||
val label = ts.toUtcDate.toString
|
||||
MetaProposal(
|
||||
MetaProposalType.DocDate,
|
||||
Candidate(IdRef(Ident.unsafe(label), label), origin.toSet)
|
||||
)
|
||||
}
|
||||
|
||||
def parseDate(cand: Candidate): Option[LocalDate] =
|
||||
parseDate(cand.ref.id)
|
||||
|
||||
|
@ -38,6 +38,9 @@ case class MetaProposalList private (proposals: List[MetaProposal]) {
|
||||
def change(f: MetaProposal => MetaProposal): MetaProposalList =
|
||||
new MetaProposalList(proposals.map(f))
|
||||
|
||||
def filter(f: MetaProposal => Boolean): MetaProposalList =
|
||||
new MetaProposalList(proposals.filter(f))
|
||||
|
||||
def sortByWeights: MetaProposalList =
|
||||
change(_.sortByWeight)
|
||||
}
|
||||
|
@ -42,10 +42,12 @@ object MetaProposalListTest extends SimpleTestSuite {
|
||||
test("sort by weights") {
|
||||
val cand1 = Candidate(IdRef(Ident.unsafe("123"), "name"), Set.empty, Some(0.1))
|
||||
val cand2 = Candidate(IdRef(Ident.unsafe("456"), "name"), Set.empty, Some(0.05))
|
||||
val mpl = MetaProposalList.of(
|
||||
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand1)),
|
||||
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand2))
|
||||
).sortByWeights
|
||||
val mpl = MetaProposalList
|
||||
.of(
|
||||
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand1)),
|
||||
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand2))
|
||||
)
|
||||
.sortByWeights
|
||||
|
||||
val candidates = mpl.find(MetaProposalType.CorrOrg).get.values
|
||||
assertEquals(candidates.head, cand2)
|
||||
@ -55,10 +57,12 @@ object MetaProposalListTest extends SimpleTestSuite {
|
||||
test("sort by weights: unset is last") {
|
||||
val cand1 = Candidate(IdRef(Ident.unsafe("123"), "name"), Set.empty, Some(0.1))
|
||||
val cand2 = Candidate(IdRef(Ident.unsafe("456"), "name"), Set.empty)
|
||||
val mpl = MetaProposalList.of(
|
||||
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand1)),
|
||||
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand2))
|
||||
).sortByWeights
|
||||
val mpl = MetaProposalList
|
||||
.of(
|
||||
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand1)),
|
||||
MetaProposal(MetaProposalType.CorrOrg, NonEmptyList.of(cand2))
|
||||
)
|
||||
.sortByWeights
|
||||
|
||||
val candidates = mpl.find(MetaProposalType.CorrOrg).get.values
|
||||
assertEquals(candidates.head, cand1)
|
||||
|
Reference in New Issue
Block a user