Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

496 extend comment syntax in khiops dictionaries #503

Open
wants to merge 13 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 85 additions & 16 deletions src/Learning/KWData/KWAttributeBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ boolean KWAttributeBlock::Check() const
if (not KWClass::CheckName(GetName(), KWClass::AttributeBlock, this))
bOk = false;

// Verification du Label
if (not KWClass::CheckLabel(GetLabel(), KWClass::AttributeBlock, this))
bOk = false;

// Verification des commentaires
if (not KWClass::CheckComments(GetComments(), KWClass::AttributeBlock, this))
bOk = false;

// Verification des commentaires internes
if (not KWClass::CheckComments(GetInternalComments(), KWClass::AttributeBlock, this))
bOk = false;

// Tests de base sur la specification du block
if (bOk and firstAttribute == NULL)
{
Expand Down Expand Up @@ -746,6 +758,8 @@ longint KWAttributeBlock::GetUsedMemory() const
lUsedMemory = sizeof(KWAttributeBlock);
lUsedMemory += usName.GetUsedMemory();
lUsedMemory += usLabel.GetUsedMemory();
lUsedMemory += svComments.GetUsedMemory();
lUsedMemory += svInternalComments.GetUsedMemory();
lUsedMemory += metaData.GetUsedMemory() - sizeof(KWMetaData);

// Prise en compte de la regle de derivation
Expand Down Expand Up @@ -778,42 +792,88 @@ longint KWAttributeBlock::ComputeHashValue() const

void KWAttributeBlock::Write(ostream& ost) const
{
KWAttribute* secondAttribute;
KWClass* parentClass;
KWAttribute* attribute;
int i;

ost << '{';
if (firstAttribute != NULL)
// Commentaires prededents le debut du bloc
Copy link
Collaborator

@popescu-v popescu-v Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/prededents/precedant/ (present participle).

for (i = 0; i < GetComments()->GetSize(); i++)
ost << "\t// " << GetComments()->GetAt(i) << "\n";
ost << "\t{\n";

// Attributs du bloc
parentClass = GetParentClass();
attribute = firstAttribute;
while (attribute != NULL)
{
ost << firstAttribute->GetName();
// Ecriture de l'attribut
ost << *attribute << "\n";

// Arret si derniere variable du bloc trouvee
if (attribute == lastAttribute)
break;

// Passage a l'attribut suivant
parentClass->GetNextAttribute(attribute);
}

// Acces au deuxieme attribut
secondAttribute = firstAttribute;
if (GetParentClass() != NULL)
GetParentClass()->GetNextAttribute(secondAttribute);
// Commentaires internes precedents la fin du bloc
for (i = 0; i < GetInternalComments()->GetSize(); i++)
ost << "\t// " << GetInternalComments()->GetAt(i) << "\n";
ost << "\t}";

// Si au moins trois attributs
if (lastAttribute != NULL and secondAttribute != NULL and lastAttribute != secondAttribute)
ost << ",..., ";
// Nom du bloc
ost << "\t" << KWClass::GetExternalName(GetName());
ost << "\t";

// Dernier attribut si au moins deux attributs
if (lastAttribute != NULL and lastAttribute != firstAttribute)
ost << ", " + lastAttribute->GetName();
// Regle de derivation
if (GetDerivationRule() != NULL)
{
// Dans le cas de la regle predefinie de Reference, on n'utilise pas le signe '='
if (GetDerivationRule()->GetName() != KWDerivationRule::GetReferenceRuleName())
ost << " = ";
GetDerivationRule()->WriteUsedRule(ost);
}
ost << "}\t" << GetName() << endl;

// Fin de declaration
ost << "\t;";

// Meta-donnees
if (GetConstMetaData()->GetKeyNumber() > 0)
{
ost << ' ';
GetConstMetaData()->Write(ost);
}
ost << "\t";

// Libelle
if (GetLabel() != "")
ost << "// " << GetLabel();
}

void KWAttributeBlock::WriteJSONFields(JSONFile* fJSON)
{
KWClass* parentClass;
KWAttribute* attribute;
ALString sOutputString;
int i;

// Nom
fJSON->WriteKeyString("blockName", GetName());

// Commentaire
// Libelle
if (GetLabel() != "")
fJSON->WriteKeyString("label", GetLabel());

// Commentaire
if (GetComments()->GetSize() > 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would discard the test and write the comments array anyway (even if empty).

{
fJSON->BeginKeyArray("comments");
for (i = 0; i < GetComments()->GetSize(); i++)
fJSON->WriteString(GetComments()->GetAt(i));
fJSON->EndArray();
}

// Regle de derivation
if (kwdrRule != NULL)
{
Expand Down Expand Up @@ -842,6 +902,15 @@ void KWAttributeBlock::WriteJSONFields(JSONFile* fJSON)
parentClass->GetNextAttribute(attribute);
}
fJSON->EndArray();

// Commentaires internes
if (GetInternalComments()->GetSize() > 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem, I would write the internalComments array anyway, even if empty. If the if is kept, then the BeginKeyArray and EndArray could be added outside the if block?

{
fJSON->BeginKeyArray("internalComments");
for (i = 0; i < GetInternalComments()->GetSize(); i++)
fJSON->WriteString(GetInternalComments()->GetAt(i));
fJSON->EndArray();
}
}

const ALString KWAttributeBlock::GetClassLabel() const
Expand Down
33 changes: 33 additions & 0 deletions src/Learning/KWData/KWAttributeBlock.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,20 @@ class KWAttributeBlock : public KWDataItem
void ImportMetaDataFrom(const KWAttributeBlock* sourceAttributeBlock);

// Libelle
// Fin de ligne prefixee par '//' suivant la declaration du bloc d'attributs dans le fichier dictionnaire
const ALString& GetLabel() const;
void SetLabel(const ALString& sValue);

// Commentaires
// Ensemble des lignes prefixees par '//' precedent le debut du bloc d'attributs '{' dans le fichier dictionnaire
const StringVector* GetComments() const;
void SetComments(const StringVector* svValue);

// Commentaires internes
// Ensemble des lignes prefixees par '//' precedent la fin du bloc d'attributs '}' dans le fichier dictionnaire
const StringVector* GetInternalComments() const;
void SetInternalComments(const StringVector* svValue);

/////////////////////////////////////////////////////////
// Informations de specification du bloc, suite a sa
// creation depuis la classe englobante
Expand Down Expand Up @@ -259,6 +270,8 @@ class KWAttributeBlock : public KWDataItem
// Specifications du bloc
KWCDUniqueString usName;
KWCDUniqueString usLabel;
StringVector svComments;
StringVector svInternalComments;
KWDerivationRule* kwdrRule;
KWMetaData metaData;

Expand Down Expand Up @@ -373,6 +386,26 @@ inline void KWAttributeBlock::SetLabel(const ALString& sValue)
usLabel.SetValue(sValue);
}

inline const StringVector* KWAttributeBlock::GetComments() const
{
return &svComments;
}

inline void KWAttributeBlock::SetComments(const StringVector* svValue)
{
svComments.CopyFrom(svValue);
}

inline const StringVector* KWAttributeBlock::GetInternalComments() const
{
return &svInternalComments;
}

inline void KWAttributeBlock::SetInternalComments(const StringVector* svValue)
{
svInternalComments.CopyFrom(svValue);
}

inline KWAttribute* KWAttributeBlock::GetFirstAttribute() const
{
return firstAttribute;
Expand Down
59 changes: 12 additions & 47 deletions src/Learning/KWData/KWClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1583,6 +1583,8 @@ void KWClass::CopyFrom(const KWClass* aSource)
attributeBlock->GetDerivationRule()->Clone());
copyAttributeBlock->GetMetaData()->CopyFrom(attributeBlock->GetConstMetaData());
copyAttributeBlock->SetLabel(attributeBlock->GetLabel());
copyAttributeBlock->SetComments(attributeBlock->GetComments());
copyAttributeBlock->SetInternalComments(attributeBlock->GetInternalComments());
}
}

Expand Down Expand Up @@ -1816,7 +1818,7 @@ void KWClass::Write(ostream& ost) const
KWAttributeBlock* attributeBlock;
int i;

// Impression de l'entete de la classe
// Entete de la classe
ost << "\n";
if (GetLabel() != "")
ost << "// " << GetLabel() << "\n";
Expand Down Expand Up @@ -1847,59 +1849,22 @@ void KWClass::Write(ostream& ost) const
}
ost << "{\n";

// Impression de tous les attributs
// Attributs et blocs d'attributs
attribute = GetHeadAttribute();
while (attribute != NULL)
{
// Debut de bloc si necessaire
// Bloc, au moment du premier attribut du bloc
if (attribute->IsFirstInBlock())
ost << "\t{\n";

// Impression de l'attribut
ost << *attribute << "\n";

// Fin de bloc si necessaire
if (attribute->IsLastInBlock())
{
ost << "\t}";

// Nom du bloc
attributeBlock = attribute->GetAttributeBlock();
ost << "\t" << KWClass::GetExternalName(attributeBlock->GetName());
ost << "\t";

// Regle de derivation
if (attributeBlock->GetDerivationRule() != NULL)
{
// Dans le cas de la regle predefinie de Reference, on n'utilise pas le signe '='
if (attributeBlock->GetDerivationRule()->GetName() !=
KWDerivationRule::GetReferenceRuleName())
ost << " = ";
attributeBlock->GetDerivationRule()->WriteUsedRule(ost);
}

// Fin de declaration
ost << "\t;";

// Meta-donnees
if (attributeBlock->GetConstMetaData()->GetKeyNumber() > 0)
{
ost << ' ';
attributeBlock->GetConstMetaData()->Write(ost);
}
ost << "\t";

// Commentaire
if (attributeBlock->GetLabel() != "")
ost << "// " << attributeBlock->GetLabel();
ost << "\n";
}
ost << *attribute->GetAttributeBlock() << "\n";
// Attribut, s'il n'est pas dans un bloc
else if (not attribute->IsInBlock())
ost << *attribute << "\n";

// Attribut suivant
GetNextAttribute(attribute);
}

// Impression de la fin de la classe
// Commentaire internes
for (i = 0; i < GetInternalComments()->GetSize(); i++)
ost << "\t// " << GetInternalComments()->GetAt(i) << "\n";
ost << "};\n";
Expand Down Expand Up @@ -1948,10 +1913,10 @@ void KWClass::WriteJSONFields(JSONFile* fJSON)
attribute = GetHeadAttribute();
while (attribute != NULL)
{
// Debut de bloc si necessaire
// Bloc, au moment du premier attribut du bloc
if (attribute->IsFirstInBlock())
attribute->GetAttributeBlock()->WriteJSONReport(fJSON);
// Impression de l'attribut s'il n'est pas dans un bloc
// Attribut, s'il n'est pas dans un bloc
else if (not attribute->IsInBlock())
attribute->WriteJSONReport(fJSON);

Expand Down