#!/usr/bin/perl -w $fileName = $ARGV[0]; open(IN, $fileName); @data = ; close(IN); $flag = 0; foreach(@data) { if ($_ =~/Arcs/) { $flag = 1; } if ($flag) { $_=~s/^\s+//; $_=~s/\s$//; push(@arcs, $_); }else { my($f, $s) = split(" ", $_); $s =~s/^\s+//; $s =~s/\s$_//; $s =~s/\"//g; push(@node_labels, $s); } } shift(@arcs); shift(@node_labels); #print ">>>Arcs:\n@arcs\n"; print ">>>Nodes:\n@node_labels\n"; foreach(@node_labels) { $str_node_labels .= "$_, "; } $str_node_labels =~s/\, $//; print "STR: $str_node_labels\n"; %seen = (); foreach(@arcs) { ($f, $s) = split(" ", $_); push(@uniq, $f) unless $seen{$f}++; push(@uniq, $s) unless $seen{$s}++; } #print "UNIQ: @uniq\n"; $fileName =~s/PajekIp.txt/_abs.txt/; $fileout = "$fileName"; print "FileOut: $fileout\n"; $header_comments = "\# Sample data file for a ConceptSystem. \# A concept system starts with the header ConceptSystem, followed optionally by its name. \# Each concept system is defined with 4 sections starting with the following keywords in their order: \# Concept Categories, Relation Models, Concepts, Relations. \# Sections with no contents should be left empty, but still need the keywords. \# Each definition occupies one line. Lines starting with \"#\" are comments. \# Spaces, tabs, seperation symbols such as \":,-{}()\", and blank lines are ignored.\n"; print "$header_comments\n"; print "ConceptSystem: $fileout\n"; $concept_categories = "ConceptCategories: \# If not specified, then there's one default category."; print "$concept_categories\n"; print "\{ $str_node_labels \}"; $relation_models = "RelationModels: \# If not specified, then there's one default label which is Undirected. \#-------------------------------------------------------- \# Label Directed/Undirected R0: Undirected"; print "$relation_models\n"; print "\n\nConcepts: Categorized Ranked Valued\n"; $concept_category = "\# Specify the non-case-sensitive keywords (Categorized, Ranked, Valued) \# respectively in above line if defined for each concept. \#-------------------------------------------------------- \# No. Label Weight ([1, 10])"; print "$concept_category\n"; $nctr = 0; foreach(@uniq) { print " $_:\t $node_labels[$nctr] \t \t 10\n"; $nctr++; } $rel_wt = "\nRelations: Labeled Weighted \# Specify the non-case-sensitive keywords (Labeled, Weighted) \# respectively in above line if defined for each relation. \#-------------------------------------------------------- \# Label Concepts Weight"; print "$rel_wt\n"; foreach(@arcs) { ($f, $s) = split(" ", $_); $str = " R0\( $f, $s\)\t\t 1"; print "$str\n"; } open(OUT, ">$fileout"); print OUT"$header_comments\n"; print OUT"ConceptSystem: $fileout\n"; print OUT"$concept_categories\n"; print OUT"\{ $str_node_labels \}"; print OUT"\n\n"; print OUT"$relation_models\n\n"; print OUT"Concepts: Categorized Ranked\n"; print OUT"$concept_category\n"; $nctr = 0; foreach(@uniq) { print OUT" $_:\t $node_labels[$nctr] \t \t 10\n"; $nctr++; } print OUT"$rel_wt\n"; foreach(@arcs) { ($f, $s) = split(" ", $_); $str = " R0\( $f, $s\)\t\t 1"; print OUT"$str\n"; } close(OUT);