Skip to content

Commit

Permalink
Tag.name()
Browse files Browse the repository at this point in the history
  • Loading branch information
glorieux-f committed Jan 14, 2024
1 parent eaae1e8 commit 5098a6b
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 123 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/github/oeuvres/alix/cli/Balinoms.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public String top(final int limit, TagFilter filter) {
sb.append("forme\ttype\teffectif\n");
int n = 1;
for (Entry entry : lexiq) {
sb.append(entry.form + "\t" + Tag.label(entry.flag) + "\t" + entry.count + "\n");
sb.append(entry.form + "\t" + Tag.name(entry.flag) + "\t" + entry.count + "\n");
if (n == limit)
break;
n++;
Expand Down
236 changes: 118 additions & 118 deletions src/main/java/com/github/oeuvres/alix/lucene/analysis/CharsDic.java
Original file line number Diff line number Diff line change
@@ -1,118 +1,118 @@
/*
* Alix, A Lucene Indexer for XML documents.
*
* Copyright 2009 Pierre Dittgen <[email protected]>
* Frédéric Glorieux <[email protected]>
* Copyright 2016 Frédéric Glorieux <[email protected]>
*
* Alix is a java library to index and search XML text documents
* with Lucene https://lucene.apache.org/core/
* including linguistic expertness for French,
* available under Apache license.
*
* Alix has been started in 2009 under the javacrim project
* https://sf.net/projects/javacrim/
* for a java course at Inalco http://www.er-tim.fr/
* Alix continues the concepts of SDX under another licence
* «Système de Documentation XML»
* 2000-2010 Ministère de la culture et de la communication (France), AJLSM.
* http://savannah.nongnu.org/projects/sdx/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.oeuvres.alix.lucene.analysis;

import java.util.Arrays;
import java.util.HashMap;

import com.github.oeuvres.alix.fr.Tag;
import com.github.oeuvres.alix.lucene.analysis.tokenattributes.CharsAtt;

/**
* A dictionary optimized for lucene analysis using {@link CharsAtt} as key.
*/
public class CharsDic
{
private HashMap<CharsAtt, Entry> tokens = new HashMap<CharsAtt, Entry>();

public int inc(final CharsAtt token)
{
return inc(token, 0);
}

public int inc(final CharsAtt token, final int tag)
{
Entry entry = tokens.get(token);
if (entry == null) {
CharsAtt key = new CharsAtt(token);
entry = new Entry(key, tag);
tokens.put(key, entry);
}
return ++entry.count;
}

public class Entry implements Comparable<Entry>
{
private int count;
private final CharsAtt key;
private final int tag;

public Entry(final CharsAtt key, final int tag)
{
this.key = key;
this.tag = tag;
}

public CharsAtt key()
{
return key;
}

public int tag()
{
return tag;
}

public int count()
{
return count;
}

/**
* Default comparator for chain informations,
*/
@Override
public int compareTo(Entry o)
{
return o.count - count;
}

@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append(key);
if (tag > 0) sb.append(" ").append(Tag.label(tag)).append(" ");
sb.append(" (").append(count).append(")");
return sb.toString();
}
}

public Entry[] sorted()
{
Entry[] entries = new Entry[tokens.size()];
tokens.values().toArray(entries);
Arrays.sort(entries);
return entries;
}
}
/*
* Alix, A Lucene Indexer for XML documents.
*
* Copyright 2009 Pierre Dittgen <[email protected]>
* Frédéric Glorieux <[email protected]>
* Copyright 2016 Frédéric Glorieux <[email protected]>
*
* Alix is a java library to index and search XML text documents
* with Lucene https://lucene.apache.org/core/
* including linguistic expertness for French,
* available under Apache license.
*
* Alix has been started in 2009 under the javacrim project
* https://sf.net/projects/javacrim/
* for a java course at Inalco http://www.er-tim.fr/
* Alix continues the concepts of SDX under another licence
* «Système de Documentation XML»
* 2000-2010 Ministère de la culture et de la communication (France), AJLSM.
* http://savannah.nongnu.org/projects/sdx/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.oeuvres.alix.lucene.analysis;

import java.util.Arrays;
import java.util.HashMap;

import com.github.oeuvres.alix.fr.Tag;
import com.github.oeuvres.alix.lucene.analysis.tokenattributes.CharsAtt;

/**
* A dictionary optimized for lucene analysis using {@link CharsAtt} as key.
*/
public class CharsDic
{
private HashMap<CharsAtt, Entry> tokens = new HashMap<CharsAtt, Entry>();

public int inc(final CharsAtt token)
{
return inc(token, 0);
}

public int inc(final CharsAtt token, final int tag)
{
Entry entry = tokens.get(token);
if (entry == null) {
CharsAtt key = new CharsAtt(token);
entry = new Entry(key, tag);
tokens.put(key, entry);
}
return ++entry.count;
}

public class Entry implements Comparable<Entry>
{
private int count;
private final CharsAtt key;
private final int tag;

public Entry(final CharsAtt key, final int tag)
{
this.key = key;
this.tag = tag;
}

public CharsAtt key()
{
return key;
}

public int tag()
{
return tag;
}

public int count()
{
return count;
}

/**
* Default comparator for chain informations,
*/
@Override
public int compareTo(Entry o)
{
return o.count - count;
}

@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append(key);
if (tag > 0) sb.append(" ").append(Tag.name(tag)).append(" ");
sb.append(" (").append(count).append(")");
return sb.toString();
}
}

public Entry[] sorted()
{
Entry[] entries = new Entry[tokens.size()];
tokens.values().toArray(entries);
Arrays.sort(entries);
return entries;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public String toString()
StringBuilder sb = new StringBuilder();
sb.append(label);
if (tag > 0)
sb.append(" ").append(Tag.label(tag)).append(" ");
sb.append(" ").append(Tag.name(tag)).append(" ");
sb.append(" (").append(count).append(")");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public boolean incrementToken() throws IOException
}
if (tag != Tag.NULL.flag) {
posIncAtt.setPositionIncrement(0);
term.setEmpty().append(Tag.label(tag));
term.setEmpty().append(Tag.name(tag));
tag = Tag.NULL.flag;
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ public LexEntry(final Chain graph, final Chain tag, final Chain orth, final Chai
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append(Tag.label(this.tag));
sb.append(Tag.name(this.tag));
if (orth != null) sb.append(" orth=").append(orth);
if (lem != null) sb.append(" lem=").append(lem);
// if (branch) sb.append(" BRANCH");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ public String toString()
formDic.get(formId, bytes);
sb.append((pos + 1) + ". [" + formId + "] " + bytes.utf8ToString());
if (hasTag)
sb.append(" " + Tag.label(formTag[formId]));
sb.append(" " + Tag.name(formTag[formId]));
if (hasScore)
sb.append(" score=" + formScore[formId]);

Expand Down

0 comments on commit 5098a6b

Please sign in to comment.